Currently not possible. Elasticsearch will return all the nested documents
as long as one of the nested documents satisfies the query.

https://github.com/elasticsearch/elasticsearch/issues/3022

The issue is my personal #1 feature requested. Frustrating considering
there has been a working implementation since version 0.90.5. 1.0, 1.1, 1.2
and still nothing.

-- 
Ivan




On Thu, Jun 12, 2014 at 2:17 PM, Srinivasan Ramaswamy <ursva...@gmail.com>
wrote:

> any thoughts anyone ?
>
>
> On Wednesday, June 11, 2014 11:15:18 PM UTC-7, Srinivasan Ramaswamy wrote:
>>
>> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/elasticsearch/45fbf85d-4d29-4222-a72a-bf0a04d9a26d%40googlegroups.com
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQAfwARsZ7uGKkBf%2BH10jhrdw4dr5nxvHEK_FDUwQv%2BpQw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to