Jasper Kennis
Jasper Kennis

Reputation: 3062

Why is this elastic search query with must clause not returning any documents?

I'm having trouble getting this elastic search query to return the data I'd expect it to return. This is my query:

curl -XGET '0.0.0.0:9200/local/candidate/_search?routing=company_1_candidates&pretty' -d '
{
    "query":{
        "filtered": {
            "query": {
                "multi_match": {
                    "fields": [
                        "candidate_name",
                        "candidate_city",
                        "candidate_country"
                    ],
                    "query": "j",
                    "type": "phrase_prefix"
                }
            },
            "filter": {
                "bool": {
                    "must": [
                        {
                            "term": {
                                "company_id": 1
                            }
                        },
                        {
                            "term": {
                                "candidate_city": "Rotterdam"
                            }
                        }
                    ]
                }
            }
        }
    }
}'

When I run this query with only the company_id term in the must clause, I'm finding this record:

{"candidate_name":"J Kennis","candidate_id":2,"candidate_tags":[],"candidate_city":"Rotterdam","candidate_country":"Nederland","company_id":1}

But when I include the "candidate_city": "Rotterdam" bit in the query, it returns zero results. Am I missing something here?

Upvotes: 0

Views: 52

Answers (1)

GlenRSmith
GlenRSmith

Reputation: 786

Probably because the candidate_city field is being indexed with an analyzer that includes the token analyzer "lower", but the term filter is un-analyzed.

If you change your filter to "term": {"candidate_city": "rotterdam"} or "match": {"candidate_city": "Rotterdam"} you'll probably get the document back.

Upvotes: 1

Related Questions