Answer the question
In order to leave comments, you need to log in
How to correctly form a search query in Elasticsearch?
Hello!
Please help me to correctly form a search query in elastic.
There is an index for products
localhost:9200/test_index/product
Here is the mapping:
{
"test_index" : {
"mappings" : {
"product" : {
"properties" : {
"category" : {
"type" : "integer"
},
"id" : {
"type" : "integer"
},
"name" : {
"type" : "string",
"index" : "not_analyzed"
},
"property_stock" : {
"type" : "integer"
},
"skus" : {
"type" : "string",
"index" : "not_analyzed"
},
"tags" : {
"properties" : {
"group_id" : {
"type" : "integer"
},
"tag_id" : {
"type" : "integer"
}
}
},
"visible" : {
"type" : "boolean"
}
}
}
}
}
}
Answer the question
In order to leave comments, you need to log in
I myself will answer my own question :-)
I managed to do it in this way:
{
"query": {
"filtered": {
"filter": {
"bool": {
"must": [
{
"bool": {
"must": [
{"term": {"tags.group_id": 818}},
{"term": {"tags.tag_id": 223}}
]
}
},
{
"bool": {
"should": [
{"term": {"categories": 9110}},
{"term": {"categories": 9111}},
{"term": {"categories": 9114}},
{"term": {"categories": 9109}}
]
}
}
]
}
}
}
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question