Nested Query Against Different Index Mappings using ignore_unmapped

Related to this discussion: Nested query and ignore_unmapped option problem

Hi,

Using ES 5.6.1, I am trying to make a single query to multiple indices that have slightly different index mappings for a field. One index uses a nested mapping, the other does not. I am using the ignore_unmapped option in my nested query but am getting failures due to: "[nested] nested object under path [enrichments.urls] is not of nested type"

Here is a partial mapping for index1 (field is not nested):

{
    "top_level_field": {
        "properties": {
            "field": {
                "properties": {
                    "sub_field": {
                        "type": "keyword"
                    }
                }
            }
        }
    }
}

Here is a partial mapping for index2 (field is nested):

{
    "top_level_field": {
        "properties": {
            "field": {
                "type": "nested",
                "properties": {
                    "sub_field": {
                        "type": "text",
                        "analyzer": "custom_analyzer",
                        "fields": {
                            "analyzed1": {
                                "type": "text",
                                "analyzer": "custom_analyzer2"
                            },
                            "analyzed2": {
                                "type": "text",
                                "analyzer": "another_analyzer"
                            }
                        }
                    }
                }
            }
        }
    }
}

Here is a sample query targeting /index1,index2/_search

{
    "query": {
        "bool": {
            "should": [{
                "query_string": {
                    "fields": ["top_level_field.field.sub_field"],
                    "query": "pizza"
                }
            }, {
                "nested": {
                    "path": "top_level_field.field",
                    "ignore_unmapped": true,
                    "query": {
                        "query_string": {
                            "fields": ["top_level_field.field.sub_field", "top_level_field.field.sub_field.analyzed1", "top_level_field.field.sub_field.analyzed2"],
                            "query": "pizza"
                        }
                    }
                }
            }]
        }
    }
}

According to the docs, it seems like the ignore_unmapped option should allow this query to successfully execute against two fields in different indices with different mappings. Is that a correct assumption? Is there another way I should be structuring this query?

Thanks

Ying

1 Like

I am seeing the same behavior with 5.6.0. It seems like a bug, unless ignore_unmapped wasn't intended to handle this case. I have queries structured similarly to those provided by @ymao, although I've tried other variations with no luck.

I guess the bottom line is, should Elasticsearch allow me to query a field across two indices, where in one index the field is nested and in the other it is searchable but not nested?

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.