Search code examples
elasticsearchelasticsearch-6

Elasticsearch 6.2: terms query require lowercase input when searching on keyword


I've created an example index, with the following mapping:

{
    "_doc": {
        "_source": {
            "enabled": False
        },
        "properties": {
            "status": { "type": "keyword" }
        }
    }
}

And indexed a document:

{"status": "CMP"}

When searching the documents with this status with a terms query, I find no results:

{
    "query" : {
        "terms": { "status": ["CMP"]}
    }
}

However, if I make the same query by putting the input in lowercase, I will find my document:

{
    "query" : {
        "terms": { "status": ["cmp"]}
    }
}

Why is it? Since I'm searching on a keyword field, the indexed content should not be analyzed and should match an uppercase value...


Solution

  • The index and mapping creation and the search were part of a test suite. It seems that the setup part of the test suite was not executed, and the mapping was not applied to the index.

    The index was then using the default types instead of the mapping types, resulting of the use of string fields instead of keywords.

    After changing the setup method of the automated tests, the mappings are well applied to the index, and the uppercase values for the status "CMP" are now matching documents.