我有这个搜索查询:
$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'
]
]
]
]
]
];
但我无法在两个日期之间过滤结果?
任何想法如何解决这个问题?我需要更改语法吗?
答案 0 :(得分:1)
您可能需要从搜索查询中删除mappings
部分,因为它不属于那里(即仅在创建索引时才需要,而不是在搜索时)。然后你可能错过了一个filtered
查询,这应该足以让你获得一些文档。
$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'
]
]
]
]
]
]
];