Has_parent queries across multiple indices where types may not exist

(Steve) #1


If I create two indices, index_a and index_b:

$ curl localhost:9200/index_a -XPUT -d'{"mappings": {"parent-type": {}, "child-type": {"_parent": {"type": "parent-type"}}}}'

$ curl localhost:9200/index_b -XPUT -d'{"mappings": {"some-type": {}}}'

The following query gives an error:

$ curl localhost:9200/index_a,index_b/_search -d'{"query": {"has_parent": {"type": "parent-type", "query": {"match_all": {}}}}}'

{"took":172,"timed_out":false,"_shards":{"total":2,"successful":1,"failed":1,"failures":[{"index":"index_b","shard":0,"status":400,"reason":"SearchParseException[[index_b][0]: from[-1],size[-1]: Parse Failure [Failed to parse source [{\"query\": {\"has_parent\": {\"type\": \"parent-type\", \"query\": {\"match_all\": {}}}}}]]]; nested: QueryParsingException[[index_b] [has_parent] query configured 'parent_type' [parent-type] is not a valid type]; "}]},"hits":{"total":0,"max_score":null,"hits":[]}}

This isn't entirely unexpected, but is there any way to have elasticsearch treat the missing type as a negative result rather than a failure?

My larger use case is that index_a and index_b have different document types and mappings (though some fields are common to all types) but we want to run queries across them both (and I was hoping to be able to do it with "indices" filters to target queries only where they made sense). multisearch might be an answer, but isn't quite the same since we'd need to merge the results (and size/sorting applies to each targeted search individually).



(system) #2