假设我的文档具有这种结构
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查询字符串在嵌套对象中按范围搜索日期
发布评论