Search code examples
elasticsearchelasticsearch-mapping

Elasticsearch: Cannot Get Results From Keyword Field


I have a field that is mapped as text and which includes another field mapped as keyword (fields keyword). I insert data and ensure it can retrieved using any query. However, when I query the additional field (mapped as keyword), I cannot find any data at all. Here is the example (simplified):

POST people/_mapping/_doc
{
  "properties": {
    "name": {
      "type": "text"
    },
    "bio": {
      "type": "text",
      "fields": {
        "keyword": {
          "type": "keyword"
        }
      }
    }
  }
}

And here is a query:

POST people/_search
{
  "query": {
    "match": {
      "bio.keyword": "Portugal"
    }
  }
}

Same happens regardless of the casing (Portugal vs portugal). What is the reason for this behavior?


Solution

  • In elasticseach, if you have a text type field say description.

    One value of description is: He likes dog but hate cat.

    The revert index for this field is: He/like/dog/but/hate/cat

    And there is another 'keyword' field which is description.keyword, which is exactly He likes dog but hate cat.

    The keyword field requires 100% match.