function createIndex() {
return client.indices.create({
index: 'bs_index',
body: {
mappings: {
properties: {
all_prop: {
type: 'text'
},
id: {
type: 'keyword',
copy_to: 'all_prop'
},
brand: {
type: 'keyword',
copy_to: 'all_prop'
},
sale: {
type: 'keyword',
index: false
},
img: {
type: 'keyword',
index: false
},
class: {
type: 'keyword',
copy_to: 'all_prop'
},
type: {
type: 'keyword',
copy_to: 'all_prop'
},
model: {
type: 'keyword',
copy_to: 'all_prop'
},
price: {
type: 'keyword',
index: false
},
sex: {
type: 'keyword',
copy_to: 'all_prop'
},
category: {
type: 'keyword',
copy_to: 'all_prop'
},
color: {
type: 'keyword',
copy_to: 'all_prop'
},
size: {
type: 'keyword',
copy_to: 'all_prop'
},
photo: {
type: 'keyword',
index: false
},
info: {
type: 'keyword',
copy_to: 'all_prop'
}
}
}
}
})
}
GET /_search
{
"size" : 0,
"aggs": {
"my_agg": {
"aggs": {
"price": {
"terms": { "field": "price","size" : 100 }
},
"sex": {
"terms": { "field": "sex","size" : 100 }
},
"category": {
"terms": { "field": "category","size" : 100 }
},
"color": {
"terms": { "field": "color","size" : 100 }
},
"size": {
"terms": { "field": "size","size" : 100 }
},
"brand": {
"terms": { "field": "brand","size" : 100 }
}
},
"filter": {
"terms": { "size": ["10US"] }
}
}
}
}
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 15,
"successful": 15,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 268,
"relation": "eq"
},
"max_score": null,
"hits": []
},
"aggregations": {
"my_agg": {
"doc_count": 2,
"size": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "10US",
"doc_count": 2
}
]
},
"color": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "Коричневый",
"doc_count": 1
},
{
"key": "Красный",
"doc_count": 1
}
]
},
"price": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "11290",
"doc_count": 1
},
{
"key": "4890",
"doc_count": 1
}
]
},
"sex": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "Мужской",
"doc_count": 2
}
]
},
"category": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "Кроссовки",
"doc_count": 2
}
]
},
"brand": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "Nike",
"doc_count": 2
}
]
}
}
}
}
GET /_search
{
"size" : 0,
"aggs": {
"size": {
"aggs": {
"price": {
"terms": { "field": "price","size" : 100 }
},
"sex": {
"terms": { "field": "sex","size" : 100 }
},
"category": {
"terms": { "field": "category","size" : 100 }
},
"color": {
"terms": { "field": "color","size" : 100 }
},
"brand": {
"terms": { "field": "brand","size" : 100 }
}
},
"filter": {
"bool" : {
"filter" : [
{
"terms": { "size": ["10US"] }
}
]
}
}
},
"color": {
"aggs": {
"size": {
"terms": { "field": "size","size" : 100 }
}
},
"filter": {
"bool" : {
"filter" : [
]
}
}
}
}
}
GET /_search
{
"size" : 0,
"aggs": {
"inavtive": {
"aggs": {
"price": {
"terms": { "field": "price","size" : 100 }
},
"sex": {
"terms": { "field": "sex","size" : 100 }
},
"category": {
"terms": { "field": "category","size" : 100 }
},
"brand": {
"terms": { "field": "brand","size" : 100 }
}
},
"filter": {
"bool" : {
"filter" : [
{
"terms": { "size": ["10US"] }
},
{
"terms": { "color": ["Красный"] }
}
]
}
}
},
"size": {
"aggs": {
"size": {
"terms": { "field": "size","size" : 100 }
}
},
"filter": {
"bool" : {
"filter" : [
{
"terms": { "color": ["Красный"] }
}
]
}
}
},
"color": {
"aggs": {
"size": {
"terms": { "field": "color","size" : 100 }
}
},
"filter": {
"bool" : {
"filter" : [
{
"terms": { "size": ["10US"] }
}
]
}
}
}
}
}