Elasticsearch中的嵌套查询

编程入门 行业动态 更新时间:2024-10-17 19:28:42
本文介绍了Elasticsearch中的嵌套查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我无法在使用Elasticsearch的嵌套查询时遇到问题(如果我删除其中一个查询字符串,则可以使用)。我要解决的问题是我有一个包含关闭列表的文档(关闭)。我想在一个条件满足另一个值的闭包列表中搜索一个值。那只是从argan = 1

Im having problem getting a nested query working with elasticsearch (If i remove one of the query-strings it works). the problem I am trying to solve is that i have a document (Closure) containing a list of closures. And I want to search for a value in the list of closures where another value is meet by a condition. That is only take value from a closures where 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" } } ] } }}

我正在收到此错误响应;

Im getting this error-response;

{ "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对我做错了什么有什么想法?

Annyone have any idea on what im doing wrong?

推荐答案

您的查询无效查询。您需要使用适当的复合查询将其他查询组合在一起,不能只使用逗号并添加仅支持一个查询的另一个查询。

Your query is not a valid query. You need to use a proper compound query to combine other queries together, you can't just use a comma and add another query where only one is supported.

您能够 例如,使用布尔查询并具有两个must子句,几乎是您的两个query_string。也许您甚至可以切换到使用过滤器,并进行过滤查询。 我将看一下本文中的示例: www.spacevatican/2012/6/3/fun-with-elasticsearch-s-children-andnested-documents/ 。

You can for instance use a bool query and have two must clauses, pretty much your two query_string. Or maybe you can even switch to using filters, and have a filtered query. I'd have a look at the examples on this article: www.spacevatican/2012/6/3/fun-with-elasticsearch-s-children-and-nested-documents/.

更多推荐

Elasticsearch中的嵌套查询

本文发布于:2023-10-23 05:34:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1519941.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:嵌套   Elasticsearch

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!