Elasticsearch keyword and lowercase and aggregation

I previously saved several fields with "keyword" display. But, they are dealing with sststive.

To solve this problem, you can use a parser like

{
  "index": {
    "analysis": {
      "analyzer": {
        "keyword_lowercase": {
          "tokenizer": "keyword",
          "filter": [
            "lowercase"
          ]
        }
      }
    }
  }
}

      

with display

{
  "properties": {
    "field": {
      "type": "string",
      "analyzer": "keyword_lowercase"
    }
  }
}

      

But then the Unit does not work on time.

Thrown: java.lang.IllegalArgumentException: By default, fields are disabled in text fields. Set fielddata = true to [a] to load field data into memory by de-inverting the inverted index. Note that this can, however, use significant memory.

It works with type = keyword mapping, but type = keyword doesn't allow the parser.

How do I index it as a lowercase keyword, but can still use aggregation without setting fielddata = true?

+3


source to share


1 answer


If you are using ES 5.2 or higher, you can now use normalizer

s
for fields keyword

. Just declare your index and mapping settings like this and you're good to go



PUT index
{
  "settings": {
    "analysis": {
      "normalizer": {
        "keyword_lowercase": {
          "type": "custom",
          "filter": ["lowercase"]
        }
      }
    }
  },
  "mappings": {
    "type": {
      "properties": {
        "field": {
          "type": "keyword",
          "normalizer": "keyword_lowercase"
        }
      }
    }
  }
}

      

+4


source







All Articles