Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You are correct that it should only find documents where the nested document has value1 AND value2.</p> <p>You can observe this is how elasticsearch behaves by running the following in <a href="https://chrome.google.com/webstore/detail/sense/doinijnbnggojdlcjifpdckfokbbfpbo?hl=en" rel="nofollow">sense (chrome plugin)</a>:</p> <pre><code>PUT http://localhost:9200/nested_example { "mappings": { "indexentry" : { "properties": { "nestedCollection": { "type": "nested", "properties": { "prop1" : { "type": "string", "index": "not_analyzed" }, "prop2" : { "type": "string", "index": "not_analyzed" } } } } } } } POST http://localhost:9200/nested_example/indexentry/1 { "nestedCollection": [ { "prop1" : "A", "prop2" : "A" }, { "prop1" : "B", "prop2" : "B" } ] } POST http://localhost:9200/nested_example/indexentry/2 { "nestedCollection": [ { "prop1" : "C", "prop2" : "C" }, { "prop1" : "D", "prop2" : "D" } ] } POST http://localhost:9200/nested_example/indexentry/_search { "query": { "nested": { "path": "nestedCollection", "query": { "bool": { "must": [ { "term": { "nestedCollection.prop1": { "value": "A" } } }, { "term": { "nestedCollection.prop2": { "value": "A" } } } ] } } } } } </code></pre> <p>The previous query will only find document <code>1</code> but as soon as you change the term query for <code>nestedColleciton.prop2</code> to find <code>B</code> instead of <code>A</code> you will no longer get any response as expected. </p> <p>If I update the example to be more true to your mappings and queries I cannot reproduce the behaviour your witnessing:</p> <pre><code>PUT http://localhost:9200/nested_example { "settings": { "analysis": { "tokenizer": { "my_ngram": { "type": "nGram", "min_gram": "1", "max_gram": "15" } }, "analyzer": { "my_index_analyzer_1": { "type": "custom", "tokenizer": "my_ngram", "filters": [ "lowercase" ] }, "my_search_analyzer_1": { "type": "custom", "tokenizer": "whitespace", "filters": [ "lowercase" ] } } } }, "mappings": { "indexentry": { "properties": { "nestedCollection": { "type": "nested", "properties": { "prop1": { "type": "string", "index_analyzer": "my_index_analyzer_1", "search_analyzer": "my_search_analyzer_1" }, "prop2": { "type": "string", "analyzer": "keyword" } } } } } } } POST http://localhost:9200/nested_example/indexentry/1 { "nestedCollection": [ { "prop1" : "value1", "prop2" : "value1" }, { "prop1" : "value2", "prop2" : "value2" } ] } POST http://localhost:9200/nested_example/indexentry/2 { "nestedCollection": [ { "prop1" : "value3", "prop2" : "value3" }, { "prop1" : "value4", "prop2" : "value4" } ] } POST http://localhost:9200/nested_example/indexentry/_search { "query": { "nested": { "path": "nestedCollection", "query": { "bool": { "must": [ { "term": { "prop1": { "value": "value1" } } }, { "query_string": { "fields": [ "prop2" ], "query": "value1" } } ] } } } } } </code></pre> <p>Can you update the previous example to better reproduce your situation?</p> <p>Final note in NEST you can rewrite the query as:</p> <pre class="lang-cs prettyprint-override"><code>client.Search&lt;IndexEntry1&gt;(d =&gt; d .Query(query =&gt; query .Nested(n =&gt; n .Path(p =&gt; p.NestedProperty1) .Query(q =&gt; q.Term(p =&gt; p.NestedProperty1.First().Member1, "value1") &amp;&amp; q.QueryString(s =&gt; s .OnField(p =&gt; p.NestedPropery1.First().Member2) .Query("value2") ) ) ) ); </code></pre> <p>Strongly typed and with less nesting going on.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload