Elasticsearch query

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

我正在尝试使用query_string编写查询以检索嵌套对象的数据查询.

I am trying to write a query using query_string to retrieve data querying by nested objects.

我要执行的查询示例如下:

An example of query I would like to do is this one:

{ "query": { "query_string": { "query": "a.id:2" } } }

其中"a"是嵌套对象,"id"是"a"的字段.

Where "a" is a nested object, and "id" is a field of "a".

我知道我可以使用嵌套查询成功地执行此任务,编写如下查询:

I know I can successfully perform this task using using a nested query, writing a query like:

{ "nested": { "path": "a" "query_string": { "query": "a.id:2" } } }

但是,我想避免这种情况.我不想自己弄清楚用户正在搜索嵌套字段并修改查询.我尝试使用"fields"参数,但它似乎不适用于嵌套对象.

However, I would like to avoid it. I don't want to figure out by myself that the user is searching for a nested field and modify the query. I tried to use the "fields" parameter, but it looks like it doesn't work with nested objects.

是否可以使用"query_string"查询直接编写此查询?有可能获得什么语义?(例如,如果我写"a.id:2 AND a.b:10",我是在匹配同一对象还是不同对象中的两个字段?)

Is it possible to write this query directly using "query_string" queries? What semantic is it possible to obtain? (for instance, if I write "a.id:2 AND a.b:10" I am matching the two fields in the same object or in different objects?)

推荐答案

我进行了更多研究,发现可以通过在映射中将include_in_parent设置为true来实现.

I was doing more research and found this can be achieved by setting the include_in_parent setting to true in the mapping.

现在您应该可以进行

{ "query": { "query_string": { "query": "fields.fieldvalue:sometext" } } }

例如:-

"mappings": { "documentmetadatavalue": { "properties": { "id": { "type": "string" }, "fields": { "type": "nested", "include_in_parent": true, "properties": { "fieldId": {"type": "string"}, "fieldvalue": {"type": "string"} } } } } }

让我知道是否有帮助.

更多推荐

Elasticsearch query

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

发布评论

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

>www.elefans.com

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