我有这个搜索查询:
$params = [
'index' => 'veenendaal2',
'type' => 'passanten2',
'size' => $size,
'body' => [
'query' => [
"match_all" => [],
'filter' => [
'range' => [
'Tijdsperiode' => [
'gte' => '2016-01-30 01:00:00',
'lte' => '2016-01-30 08:00:00'
]
]
]
],
'mappings' => [
'_default_' => [
'properties' => [
'Tijdsperiode' => [
'type' => 'date',
'format' => 'yyyy-MM-dd HH:mm:ss'
]
]
]
]
]
];
但我不能让它过滤两个日期之间的结果?
有什么解决办法吗?我需要更改语法吗?
最佳答案
您可能需要从搜索查询中删除 mappings
部分,因为它不属于那里(即它只在创建索引时需要,而不是在搜索时需要)。那么您可能错过了一个过滤的
查询,这应该足以让您获得一些文档。
$params = [
'index' => 'veenendaal2',
'type' => 'passanten2',
'size' => $size,
'body' => [
'query' => [
'filtered' => [
'filter' => [
'range' => [
'Tijdsperiode' => [
'gte' => '2016-01-30 01:00:00',
'lte' => '2016-01-30 08:00:00'
]
]
]
]
]
]
];
关于php - Elasticsearch范围查询(PHP客户端),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36102153/