Reputation: 355
I do have a problem with a filtered query. When I run the following query :
{
"query":{
"filtered":{
"query":{
"regexp":{
"name":"chri.*"
}
},
"filter":{
"bool":{
"must":[
{"term": { "accountNonLocked": "false" }}
]
}
}
}
},"fields" : ["name", "id", "accountNonLocked","role"],
"from" : 0,
"size" : 10
}
I got to following response
{
"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"
]
}
}
]}
}
But when I add a filter on the role like this :
{
"query":{
"filtered":{
"query":{
"regexp":{
"name":"chri.*"
}
},
"filter":{
"bool":{
"must":[
{"term": { "accountNonLocked": "false" }},
{"term": { "role": "CANDIDATE" }}
]
}
}
}
},"fields" : ["name", "id", "accountNonLocked","role"],
"from" : 0,
"size" : 10
}
Then I got an empty result :
{
"took": 3,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 0,
"max_score": null,
"hits": []
}
}
Does anyone can tell me what I am doing wrong ?
Upvotes: 2
Views: 96
Reputation: 217254
Your role
field is probably an analyzed
string.
So either try with a lowercase value like in
{"term": { "role": "candidate" }}
or change the mapping of your role
field to be not_analyzed
(you'll need to reindex your data for the change to take effect)
Upvotes: 2