Term Query to Exclude Others

Hi this may seem too elementary but I am also new to elasticsearch, so please bare with me. Say I have two documents, one with "name" : "ABC Company" and one with "name" : "ABC". Setting for the "name" field is of "text" type with Standard analyser.

When doing a Term query like below:

{
    "query": {
        "bool": {
            "must": [{
                "term": {
                    "name": "abc"
                }
            },
            {
                "term": {
                    "name": "company"
                }
            }]
        }
    }
}

I can get exclusively the "ABC Company" document.
But doing this Term query:

{
    "query": {
        "bool": {
            "must": [{
                "term": {
                    "name": "abc"
                }
            }]
        }
    }
}

would return both documents "ABC Company" and "ABC".

How should I do the query so that I get just "ABC" to return in the second query without changing the indexing settings (e.g. adding extra keyword fields).

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.