ElasticSearch查询字符串在嵌套对象中按范围搜索日期

编程入门 行业动态 更新时间:2024-10-27 13:25:04
本文介绍了ElasticSearch查询字符串在嵌套对象中按范围搜索日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

假设我的文档具有这种结构

Suppose I have documents that have this kind of structure

{ "_index": "unittest_repositorydb_iscatalogdata_v2", "_type": "product", "_id": "Product_100092_In_81810", "_score": 2.0794415, "_source": { "p": { "effective_dt": null, "code_s_lower": "B19_9394_Exp", "expiration_dt": "2020-05-16T00:00:00.0000000Z" }, "catId_s": "fNXXb5CRkpM" } }

我想做的是使用查询字符串按到期日期进行搜索.这是我在Kibana中所做的查询:

What I want to do is search by expiration date using query string. This is the query I do in Kibana:

GET _search { "query": { "query_string": { "query": "catId_s:fNXXb5CRkpM AND p.expiration_dt:[2020\\-05\\-10T00\\:00\\:00Z TO 2020\\-05\\-17T00\\:00\\:00Z]", "fields": [ "p.code_s_lower^31", "p.expiration_dt", "p.effective_dt" ], "lenient": true } }, "from": 0, "size": 50, "_source": [ "catId_s", "p.code_s_lower", "p.expiration_dt", "p.effective_dt" ] }

但这不会返回任何结果.我发现的一件事是,如果我将日期移到嵌套对象p的外部,并将其与catId_s放在同一级别,则搜索有效.我做错了什么吗?我需要做一些特别的事情来搜索嵌套对象吗?

But this does not return any results. One thing I found was if I move the dates outside the nested object p and putting them at the same level as catId_s, the search was working. Is there any thing I am doing wrong? Do I need to do something special to search in nested objects?

ES的版本为版本:5.3.0,内部版本:3adb13b/2017-03-23T03:31:50.652Z,JVM:1.8.0_231

推荐答案

如果您的经验丰富.dt.的类型为 date ,建议应用适当的范围查询:

If your exp. dt. is of type date, it's recommended to apply a proper range query:

{ "query":{ "bool":{ "must":[ { "nested":{ "path":"p", "query":{ "bool":{ "must":[ { "range":{ "p.expiration_dt":{ "gte":"2020-05-10T00:00:00Z", "lte":"2020-05-17T00:00:00Z" } } } ] } } } } ] } } }

正如@Val所指出的,应将其余的查询字符串拆分并放入嵌套的 must 中.

As @Val pointed out, the rest of your query string should be split and put into the nested must.

更多推荐

ElasticSearch查询字符串在嵌套对象中按范围搜索日期

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

发布评论

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

>www.elefans.com

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