gpt4 book ai didi

elasticsearch - 为什么我在 Elasticsearch 中的日期查询失败?

转载 作者:行者123 更新时间:2023-12-02 22:55:58 26 4
gpt4 key购买 nike

我目前正在关注一个网络教程,当我运行时:

GET /product/_doc/_search
{
"query": {
"range": {
"in_stock": {
"gte": 1,
"lte": 5
}
}
}
}

我得到了一堆记录,包括:
  {
"_index" : "product",
"_type" : "_doc",
"_id" : "366",
"_score" : 1.0,
"_source" : {
"name" : "Eggplant - Baby",
"price" : 58,
"in_stock" : 1,
"sold" : 187,
"tags" : [ ],
"description" : "Mauris sit amet eros. Suspendisse accumsan tortor quis turpis. Sed ante. Vivamus tortor. Duis mattis egestas metus. Aenean fermentum. Donec ut mauris eget massa tempor convallis. Nulla neque libero, convallis eget, eleifend luctus, ultricies eu, nibh.",
"is_active" : false,
"created" : "2016/01/03"
}
},

当我运行时:
GET /product/_doc/_search
{
"query": {
"range": {
"created": {
"gte": "2010/01/01"
}
}
}
}

在相同的数据集中,我得到:
{
"took" : 2,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : 0,
"max_score" : null,
"hits" : [ ]
}
}

为什么我的查询命中率为零?我知道搜索正在扫描创建日期大于 2010/01/01 的记录,因此它至少不应该匹配 id 366?

编辑:

这是我的映射 - 它似乎是日期类型:
{
"product" : {
"aliases" : { },
"mappings" : {
"_doc" : {
"dynamic" : "false",
"properties" : {
"created " : {
"type" : "date",
"format" : "yyyy/MM/dd HH:mm:ss||yyyy/MM/dd"
},
"description" : {
"type" : "text"
},
"discount" : {
"type" : "integer"
},
"in_stock" : {
"type" : "integer"
},
"is_active" : {
"type" : "boolean"
},
"name" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword"
}
}
},
"price" : {
"type" : "integer"
},
"sold" : {
"type" : "long"
},
"tags" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword"
}
}
}
}
}
},
"settings" : {
"index" : {
"creation_date" : "1551151769380",
"number_of_shards" : "5",
"number_of_replicas" : "1",
"uuid" : "3YTYcG-9TPeT_3jXfX5IMA",
"version" : {
"created" : "6060199"
},
"provided_name" : "product"
}
}
}
}

最佳答案

您的属性名称中有错字。在“创建”之后你有一个额外的空间:

"properties" : {
"created " : { <-- here
"type" : "date",
"format" : "yyyy/MM/dd HH:mm:ss||yyyy/MM/dd"
},

要诊断这个,你应该打电话
GET /product/_mapping

并检查您的字段 created确实映射为日期。在你的情况下,它是一个文本。

关于elasticsearch - 为什么我在 Elasticsearch 中的日期查询失败?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54974768/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com