So I've set up an index with the following mapping:

PUT test_index { "mappings": { "doc": { "properties": { "title": { "type": "text" }, "author": { "type": "text" }, "reader_stats": { "type": "join", "relations": { "book": "reader" } } } } } }

each parent document represents a book and its children represent a reader of that book. However, if I was to run:

GET test_index/_search { "query":{"match_all":{}} }

The results would be populated with both books and readers like so:

"hits" : [ { "_index" : "test_index", "_type" : "doc", "_id" : "2", "_score" : 1.0, "_source" : { "title" : "my second book", "author" : "mr author", "reader_stats" : { "name" : "book" } } }, { "_index" : "test_index", "_type" : "doc", "_id" : "7", "_score" : 1.0, "_routing" : "2", "_source" : { "name" : "michael bookworm", "clicks" : 1, "reader_stats" : { "name" : "reader", "parent" : 2 } } } ]

Is there some way I can exclude reader documents and only show books? I already used match_all in my app to grab books so it would be good if I can avoid having to change that query but I guess that's not possible.

Also I'm a bit confused as to how mappings work with join fields as there is no definition for what fields are required of child documents. For example, in my mapping there's nowhere to specify that 'reader' documents must have 'name' and 'clicks' fields. Is this correct?