#!/bin/bash # # Description: # Example that shows how applying a `match_all` `nested` query will exclude hits that do not have nested documents. # This may be related to ElasticSearch's `NestedQueryParser` and it's use of Lucene's `ToParentBlockJoinQuery` # # See: # - https://github.com/elasticsearch/elasticsearch/blob/0.90/src/main/java/org/elasticsearch/index/query/NestedQueryParser.java # - http://lucene.apache.org/core/4_3_0/join/org/apache/lucene/search/join/package-summary.html # - http://lucene.apache.org/core/4_3_0/join/org/apache/lucene/search/join/ToParentBlockJoinQuery.html # Clean curl -XDELETE http://localhost:9200/nested # Create index curl -XPOST http://localhost:9200/nested # Create nested mapping curl -XPOST http://localhost:9200/nested/type/_mapping -d ' { "type":{ "properties":{ "list":{ "type":"nested", "properties":{} } } } }' # Insert document with a nested doc curl -XPOST http://localhost:9200/nested/type/ -d ' { "list":[ { x : 1 } ] }' # Insert document without a nested doc curl -XPOST http://localhost:9200/nested/type/ -d '{}' # Assert that there are 2 documents curl http://localhost:9200/nested/type/_count # Only returns 1 hit, but expected 2 curl -XGET http://localhost:9200/nested/type/_search -d ' { "size":0, "fields":[], "query":{ "nested":{ "query":{ "match_all":{} }, "path":"list" } } }'