我在使用elasticsearch进行嵌套查询时遇到问题(如果我删除其中一个查询字符串,则可以使用)。我试图解决的问题是我有一个包含闭包列表的文档(Closure)。我想在闭包列表中搜索一个值,其中另一个值满足条件。这只是从argan = 1
的闭包中取值{"query":{
"bool":{
"must":[
{
"nested":{
"query":{
"query_string":{
"default_field": "closures.rating",
"query": "5"
},"query_string": {
"default_field": "closure.argang",
"query": "1"
}
},
"path":"closures"
}
}
]
}
}}
我得到了这个错误响应;
{
"error": "SearchPhaseExecutionException[Failed to execute phase [query], all shards failed; shardFailures {[O3wmPzFbTY6VkgvJOchpBQ][bransch_test][2]: SearchParseException[[bransch_test][2]: from[-1],size[-1]: Parse Failure [Failed to parse source [{\n \"query\":{\n \"bool\":{\n \"must\":[\n {\n \"nested\":{\n \"query\":{\n \"query_string\":{\n \"default_field\": \"closures.rating\",\n \"query\": \"5\"\n },\"query_string\": {\n \"default_field\": \"closure.argang\",\n \"query\": \"1\"\n } \n },\n \"path\":\"closures\"\n }\n }\n ]\n }\n }\n}]]]; nested: QueryParsingException[[bransch_test] [_na] query malformed, no field after start_object]; }{[O3wmPzFbTY6VkgvJOchpBQ][bransch_test][3]: SearchParseException[[bransch_test][3]: from[-1],size[-1]: Parse Failure [Failed to parse source [{\n \"query\":{\n \"bool\":{\n \"must\":[\n {\n \"nested\":{\n \"query\":{\n \"query_string\":{\n \"default_field\": \"closures.rating\",\n \"query\": \"5\"\n },\"query_string\": {\n \"default_field\": \"closure.argang\",\n \"query\": \"1\"\n } \n },\n \"path\":\"closures\"\n }\n }\n ]\n }\n }\n}]]]; nested: QueryParsingException[[bransch_test] [_na] query malformed, no field after start_object]; }{[O3wmPzFbTY6VkgvJOchpBQ][bransch_test][4]: SearchParseException[[bransch_test][4]: from[-1],size[-1]: Parse Failure [Failed to parse source [{\n \"query\":{\n \"bool\":{\n \"must\":[\n {\n \"nested\":{\n \"query\":{\n \"query_string\":{\n \"default_field\": \"closures.rating\",\n \"query\": \"5\"\n },\"query_string\": {\n \"default_field\": \"closure.argang\",\n \"query\": \"1\"\n } \n },\n \"path\":\"closures\"\n }\n }\n ]\n }\n }\n}]]]; nested: QueryParsingException[[bransch_test] [_na] query malformed, no field after start_object]; }{[O3wmPzFbTY6VkgvJOchpBQ][bransch_test][0]: SearchParseException[[bransch_test][0]: from[-1],size[-1]: Parse Failure [Failed to parse source [{\n \"query\":{\n \"bool\":{\n \"must\":[\n {\n \"nested\":{\n \"query\":{\n \"query_string\":{\n \"default_field\": \"closures.rating\",\n \"query\": \"5\"\n },\"query_string\": {\n \"default_field\": \"closure.argang\",\n \"query\": \"1\"\n } \n },\n \"path\":\"closures\"\n }\n }\n ]\n }\n }\n}]]]; nested: QueryParsingException[[bransch_test] [_na] query malformed, no field after start_object]; }{[O3wmPzFbTY6VkgvJOchpBQ][bransch_test][1]: SearchParseException[[bransch_test][1]: from[-1],size[-1]: Parse Failure [Failed to parse source [{\n \"query\":{\n \"bool\":{\n \"must\":[\n {\n \"nested\":{\n \"query\":{\n \"query_string\":{\n \"default_field\": \"closures.rating\",\n \"query\": \"5\"\n },\"query_string\": {\n \"default_field\": \"closure.argang\",\n \"query\": \"1\"\n } \n },\n \"path\":\"closures\"\n }\n }\n ]\n }\n }\n}]]]; nested: QueryParsingException[[bransch_test] [_na] query malformed, no field after start_object]; }]",
"status": 400
}
我的映射看起来像这样。
{
"closure": {
"properties": {
"name": {
"type": "string"
},
"closures": {
"type": "nested",
"properties": {
"argang": {
"type": "string"
},
"rating": {
"type": "string"
}
}
},
"coadr": {
"type": "string"
},
"telnr": {
"type": "string"
}
}
}
}
Annyone对我做错了什么有任何想法?
答案 0 :(得分:6)
您的查询不是有效查询。您需要使用正确的复合查询将其他查询组合在一起,您不能只使用逗号并添加另一个只支持一个查询的查询。
例如,您可以使用bool查询并且有两个必须子句,几乎是您的两个query_string。或者您甚至可以切换到使用过滤器,并进行过滤查询。 我将看一下本文中的示例:http://www.spacevatican.org/2012/6/3/fun-with-elasticsearch-s-children-and-nested-documents/。