gpt4 book ai didi

php - Elasticsearch日期范围不起作用

转载 作者:行者123 更新时间:2023-12-03 01:45:04 24 4
gpt4 key购买 nike

我有如下索引的记录

                    [0] => Array
(
[_index] => test_index
[_type] => cool_type
[_id] => AVy-s52Kahn1F1gX3B0K
[_score] => 1
[_source] => Array
(
[name] => TEST
[name_alias] =>
[webiste] => www.test.com
[directions] =>
[narrative] =>
[office_function] =>
[deleted_by] =>
[created_at] => 2017-06-09 11:03:27
[updated_at] => 2017-06-09 11:03:27
[deleted_at] =>
)

)
[1] => Array
(
[_index] => test_index
[_type] => cool_type
[_id] => AVy-s52Kahn1F1gX3B0L
[_score] => 1
[_source] => Array
(
[name] => new
[name_alias] =>
[webiste] => www.new.com
[directions] =>
[narrative] =>
[office_function] =>
[deleted_by] =>
[created_at] => 2017-06-18 10:00:00
[updated_at] => 2017-06-18 10:00:00
[deleted_at] =>
)

)

我只想获取给定日期之间的记录(在2个日期范围之间,最近30天的记录以及今天的记录等)。所以我已经使用Elasticsearch文档 Link编写了这样的代码。但是我无法获取记录。
$params = [
'query' => [
'match_all' => []
],
'filter' => [
'range' => [
'created_at' => [
'gte' => '2017-06-18 00:00:00',
'lte' => '2017-06-19 00:00:00'
]
]
],
'size' => 10
];

在转换为elasticsearch时会像这样转换
{
"query": {
"match_all": []
},
"filter": {
"range": {
"created_at": {
"gte": "2017-06-18 00:00:00",
"lte": "2017-06-19 00:00:00"
}
}
},
"size": 10
}

也尝试以下方式
$params = [
'query' => [
'range' => [
'created_at' => [
'gte' => '2017-06-18 00:00:00',
'lte' => '2017-06-19 00:00:00'
]
]
],
'size' => 10
];

在转换为elasticsearch时会像这样转换
{
"query": {
"range": {
"created_at": {
"gte": "2017-06-18 00:00:00",
"lte": "2017-06-19 00:00:00"
}
}
},
"size": 10
}

请帮助我。

最佳答案

您能否为我们提供有关您创建的映射的更多数据。您可能已将“created_at”字段创建为字符串,其中范围查询将不起作用。您写的查询对我来说很好。对于日期字段,您需要创建映射类型为“日期”,格式为“dateOptionalTime”。
请更改映射,然后重试相同的查询。请引用所附图片:enter image description here

我现在无法发表评论,所以发布了此答案。

关于php - Elasticsearch日期范围不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44643931/

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