I would like to exclude some documents belonging to certain category from
the results only for certain search queries. I have a ES client layer where
i am thinking of implementing this logic as a "not" filter depending on the
search query. Let me give an example.
sample index
designId: 100
tags: ["dog", "cute"]
caption : cute dog in the garden
products : [ { productId: "200", category: 1}, {productId: "201", category:
2} ]
designId: 101
tags: ["brown", "dog"]
caption : little brown dog
products : [ {productId: "202", category: 3} ]
designId: 102
tags: ["black", "dog"]
caption : little black dog
products : [ { productId: "202", category: 4}, {productId: "203", category:
5} ]
products is a nested field inside each design.
I would like to write a query to get all matches for "dog", (not for other
keywords) but filter out few categories from the result. As ES returns the
whole nested document even if only one nested document matches the query,
my expected result is
designId: 100
tags: ["dog", "cute"]
caption : cute dog in the garden
products : [ { productId: "200", category: 1}, {productId: "201", category:
2} ]
designId: 102
tags: ["black", "dog"]
caption : little black dog
products : [ { productId: "202", category: 4}, {productId: "203", category:
5} ]
Here is the query i tried but it doesn't work. Can anyone help me point out
the mistake ?
GET /_search/
{
"query": {
"filtered": {
"filter": {
"and": [
{
"not": {
"term": {
"category": 1
}
}
},
{
"not": {
"term": {
"category": 3
}
}
}
]
},
"query": {
"multi_match": {
"query": "dog",
"fields": [
"tags",
"caption"
],
"minimum_should_match": "50%"
}
}
}
}
}
--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/7293c299-16ad-420f-bcad-2e0d80681b17%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.