CopyPastor

Detecting plagiarism made easy.

Score: -1; Reported for: Open both answers

Possible Plagiarism

Plagiarized on 2018-02-18
by Dario Balinzo

Original Post

Original - Posted on 2016-12-01
by John K



            
Present in both answers; Present only in the new answer; Present only in the old answer;

You can try with a bool query, where you specify how many nested query you need in the must section:
GET test_nested/test/_search { "query": { "bool": { "must": [ {"nested" : { "path" : "tags", "query" : { "bool" : { "must" : [ { "match" : {"tags.key" : "tag1"} } ] } } }}, {"nested" : { "path" : "tags", "query" : { "bool" : { "must" : [ { "match" : {"tags.key" : "tag2"} }, { "match" : {"tags.value" : "val2"} } ] } } }} ] } } }

In this case i have one nested query for selecting all documents with key "tag1" and the second nested query to select all documents with the "tag2" and "value2".
We figured it out. The answer was to create two nested queries, instead of having two clauses to the same nested query.
{ "query":{ "bool":{ "must":[{ "nested":{ "path":"tags", "query":{ "bool":{ "must":[ {"term":{"tags.name":"name1"}}, {"term":{"tags.value":"value1"}} ] } } } }, { "nested":{ "path":"tags", "query":{ "bool":{ "must":[ {"term":{"tags.name":"name2"}}, {"term":{"tags.value":"value2"}} ] } } } }] } } }

        
Present in both answers; Present only in the new answer; Present only in the old answer;