名称为[TypeName]的inner_hit定义已存在。使用不同的inner_hit名称

时间:2016-06-29 05:35:01

标签: elasticsearch

我有一个带有以下有效负载的搜索查询: -

"query": {
    "filtered": {
        "filter": {
            "and": [
                {
                    "range": {
                        "@timestamp": {
                             "gte": "2015-01-01||/d",
                             "lte": "2016-01-01||/d"
                        }
                    }
                },
                {
                    "or": [
                        {
                            "has_child": {
                                "type": "TypeName",
                                "filter": {
                                    "term": {
                                        "eventType.raw": "some-event"
                                    }
                                },
                                "inner_hits": {
                                    "_source": "@timestamp"
                                }
                            }
                        },
                        {
                            "not": {
                                "has_child": {
                                    "type": "TypeName",
                                    "filter": {
                                        "term": {
                                            "eventType.raw": "some-event"
                                        }
                                    },
                                    "inner_hits": {
                                        "_source": "@timestamp"
                                    }
                                }
                            }
                        }
                    ]
                }
            ]
        }
    }
}

这与弹性搜索1.7一起工作正常但是使用了弹性搜索的最新稳定版本2.3.3它不能正常工作并且失败并得到以下响应: -

        "reason": {
           "type": "illegal_argument_exception",
           "reason": "inner_hit definition with the name [TypeName] already exists. Use a different inner_hit name"
        }

日志显示以下堆栈跟踪: -

nested: IllegalArgumentException[inner_hit definition with the name [TypeName] already exists. Use a different inner_hit name];
    at org.elasticsearch.search.SearchService.parseSource(SearchService.java:855)
    at org.elasticsearch.search.SearchService.createContext(SearchService.java:654)
    at org.elasticsearch.search.SearchService.createAndPutContext(SearchService.java:620)
    at org.elasticsearch.search.SearchService.executeQueryPhase(SearchService.java:371)
    at org.elasticsearch.search.action.SearchServiceTransportAction$SearchQueryTransportHandler.messageReceived(SearchServiceTransportAction.java:368)
    at org.elasticsearch.search.action.SearchServiceTransportAction$SearchQueryTransportHandler.messageReceived(SearchServiceTransportAction.java:365)
    at org.elasticsearch.transport.TransportRequestHandler.messageReceived(TransportRequestHandler.java:33)
    at org.elasticsearch.transport.RequestHandlerRegistry.processMessageReceived(RequestHandlerRegistry.java:75)
    at org.elasticsearch.transport.TransportService$4.doRun(TransportService.java:376)
    at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.IllegalArgumentException: inner_hit definition with the name [TypeName] already exists. Use a different inner_hit name
    at org.elasticsearch.search.fetch.innerhits.InnerHitsContext.addInnerHitDefinition(InnerHitsContext.java:69)
    at org.elasticsearch.index.query.QueryParseContext.addInnerHits(QueryParseContext.java:218)
    at org.elasticsearch.index.query.HasChildQueryParser.parse(HasChildQueryParser.java:155)
    at org.elasticsearch.index.query.QueryParseContext.parseInnerFilter(QueryParseContext.java:277)
    at org.elasticsearch.index.query.NotQueryParser.parse(NotQueryParser.java:69)
    at org.elasticsearch.index.query.QueryParseContext.parseInnerQuery(QueryParseContext.java:250)
    at org.elasticsearch.index.query.QueryParseContext.parseInnerFilter(QueryParseContext.java:263)
    at org.elasticsearch.index.query.OrQueryParser.parse(OrQueryParser.java:69)
    at org.elasticsearch.index.query.QueryParseContext.parseInnerQuery(QueryParseContext.java:250)
    at org.elasticsearch.index.query.QueryParseContext.parseInnerFilter(QueryParseContext.java:263)
    at org.elasticsearch.index.query.AndQueryParser.parse(AndQueryParser.java:69)
    at org.elasticsearch.index.query.QueryParseContext.parseInnerQuery(QueryParseContext.java:250)
    at org.elasticsearch.index.query.QueryParseContext.parseInnerFilter(QueryParseContext.java:263)
    at org.elasticsearch.index.query.FilteredQueryParser.parse(FilteredQueryParser.java:79)
    at org.elasticsearch.index.query.QueryParseContext.parseInnerQuery(QueryParseContext.java:250)
    at org.elasticsearch.index.query.IndexQueryParserService.innerParse(IndexQueryParserService.java:320)
    at org.elasticsearch.index.query.IndexQueryParserService.parse(IndexQueryParserService.java:223)
    at org.elasticsearch.index.query.IndexQueryParserService.parse(IndexQueryParserService.java:218)
    at org.elasticsearch.search.query.QueryParseElement.parse(QueryParseElement.java:33)
    at org.elasticsearch.search.SearchService.parseSource(SearchService.java:838)
    ... 12 more

知道这里可能出现什么问题吗?

1 个答案:

答案 0 :(得分:1)

https://discuss.elastic.co/t/inner-hits-queries-break-from-1-7-to-2-3-in-elasticsearch/54242/4?u=siddharthgoel88的弹性搜索社区引用Martijn Van的回答。

  

问题在于你有两个内部命中定义   请求使用相同的名称。默认名称基于类型   在has_child查询中。您可以提供自定义名称   在inner_hits定义中指定名称字段。 inner_hit   name在这里很重要,因为它用于响应   确定内部命中所属的inner_hit定义。

     

以下请求应该有效:

{
"query": {
    "filtered": {
        "filter": {
            "and": [
                {
                    "range": {
                        "@timestamp": {
                             "gte": "2015-01-01||/d",
                             "lte": "2016-01-01||/d"
                        }
                    }
                },
                {
                    "or": [
                        {
                            "has_child": {
                                "type": "TypeName",
                                "filter": {
                                    "term": {
                                        "eventType.raw": "some-event"
                                    }
                                },
                                "inner_hits": {
                                    "_source": "@timestamp",
                                    "name" : "inner_hit1"
                                }
                            }
                        },
                        {
                            "not": {
                                "has_child": {
                                    "type": "TypeName",
                                    "filter": {
                                        "term": {
                                            "eventType.raw": "some-event"
                                        }
                                    },
                                    "inner_hits": {
                                        "_source": "@timestamp",
                                        "name" : "inner_hit2"
                                    }
                                }
                            }
                        }
                    ]
                }
            ]
        }
    }
}
}