1

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...

1
  • I cannot reproduce this issue against a clean ES 6.2 instance. Commented Apr 10, 2018 at 10:57

3 Answers 3

1

no more @Oliver Charlesworth Now - in Elastic 6.x - you could continue to use a keyword datatype, lowercasing your text with a normalizer,doc here. However in every cases you should change your index mapping and reindex your docs

Sign up to request clarification or add additional context in comments.

2 Comments

According to the documentation the normalizer should default to null... How is it possible that my keywords are lowercased?
yes, by default is not enabled... I don't know why, You should check how your data are written before indexing, and how you ingest your data in ES
0

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.

Comments

0

The symptoms you're seeing shouldn't occur, unless something else is wrong.

A keyword index is not analysed, so your index should contain only CMP. A terms query is also not analysed, etc. so your index is searched only for CMP. Hence there should be a match.

2 Comments

Thanks Olivier for your answer, but what happened is the opposite; I find results only when the search term is 'cmp' while my index contains only 'CMP'...
@Heschoon - Hmm, yes, I misread that. I'll delete the answer while I think about this!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.