[英]Elastic Search Filtered Query with term filter
我確實遇到了過濾查詢的問題。 當我運行以下查詢時:
{
"query":{
"filtered":{
"query":{
"regexp":{
"name":"chri.*"
}
},
"filter":{
"bool":{
"must":[
{"term": { "accountNonLocked": "false" }}
]
}
}
}
},"fields" : ["name", "id", "accountNonLocked","role"],
"from" : 0,
"size" : 10
}
我得到了以下回應
{
"took": 4,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 2,
"max_score": 1,
"hits": [
{
"_index": "candidatindex",
"_type": "job",
"_id": "54c7867ecfcbbe42dc000478",
"_score": 1,
"fields": {
"name": [
"Christophe toto"
],
"accountNonLocked": [
true
],
"role": [
"DHR"
]
}
},
{
"_index": "candidatindex",
"_type": "job",
"_id": "54c7867ecfcbbe42dc000468",
"_score": 1,
"fields": {
"name": [
"Christophe Toto"
],
"accountNonLocked": [
true
],
"role": [
"CANDIDATE"
]
}
}
]}
}
但是當我在這樣的角色上添加過濾器時:
{
"query":{
"filtered":{
"query":{
"regexp":{
"name":"chri.*"
}
},
"filter":{
"bool":{
"must":[
{"term": { "accountNonLocked": "false" }},
{"term": { "role": "CANDIDATE" }}
]
}
}
}
},"fields" : ["name", "id", "accountNonLocked","role"],
"from" : 0,
"size" : 10
}
然后我得到了一個空結果:
{
"took": 3,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 0,
"max_score": null,
"hits": []
}
}
有誰可以告訴我我做錯了什么?
您的role
字段可能是經過analyzed
字符串。 所以要么嘗試使用小寫值,如
{"term": { "role": "candidate" }}
或將您的role
字段的映射更改為not_analyzed
(您需要重新索引您的數據以使更改生效)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.