我试图按时间范围查询Elasticsearch索引,另外还有一个术语匹配特定的字符串值 .
我试过这个查询,看起来非常简单:
{
"query" : {
"bool": {
"must": [
{
"match": {
"method": "/customer/help"
}
},
{
"range" : {
"startTime": {
"from" : "2015-10-20T13:00-04:00",
"to" : "2015-10-20T14:00-04:00"
}
}
}
]
}
}
}
在这种情况下,我希望给定时间范围内的所有文档的方法值也为 "/customer/help"
.
在我的结果中,我收到的时间范围内的结果,但我得到的文件具有 "method"
字段的各种值,当我只想在该字段中使用 "/customer/help"
的结果时 .
1 回答
在映射中,您需要
method
为not_analyzed
(或使用keyword
analyzer进行分析),查询应使用term
. 这样,您在方法中索引的文本将被索引为单个标记,并且term
确保您搜索的文本与method
中索引的标记完全匹配:您需要使用的查询: