smi*_*622 13 json elasticsearch
我试图按时间范围查询Elasticsearch索引,另外还有一个术语匹配特定的字符串值.
我试过这个查询,看起来非常简单:
{
"query" : {
"bool": {
"must": [
{
"match": {
"method": "/customer/help"
}
},
{
"range" : {
"startTime": {
"from" : "2015-10-20T13:00-04:00",
"to" : "2015-10-20T14:00-04:00"
}
}
}
]
}
}
}
Run Code Online (Sandbox Code Playgroud)
在这种情况下,我希望在给定时间范围内的所有文档也具有方法值"/customer/help".
在我的结果中,我收到的时间范围内的结果,但是"method"当我只想"/customer/help"在该字段中获得结果时,我会获得具有该字段的各种值的文档.
And*_*fan 22
在你的映射,你需要有method作为not_analyzed(或分析keyword仪),和查询应该使用term.通过这种方式,您在方法中索引的文本将被索引为单个标记,term并确保您搜索的文本与索引中的标记完全匹配method:
"method": {
"type": "string",
"index": "not_analyzed"
}
Run Code Online (Sandbox Code Playgroud)
您需要使用的查询:
{
"query": {
"bool": {
"must": [
{
"term": {
"method": "/customer/help"
}
},
{
"range": {
"startTime": {
"from": "2015-10-20T13:00-04:00",
"to": "2015-10-20T14:00-04:00"
}
}
}
]
}
}
}
Run Code Online (Sandbox Code Playgroud)