4

I'm trying to create an index in Elasticsearch through Python. I have a local instance of ES deployed and queries run fine. However, I have a schema. Here it is:

{
  "mappings": {
    "payment":{
      "properties":{
        "timestamp":{"type":"date"},
        "base_amount":{"type":"integer"},
        "derived_id":{"type":"keyword", "fielddata": true},
        "attempts":{"type":"integer"},
        "status":{"type":"text","fielddata":true},
        "error_code":{"type":"text","fielddata":true}
      }
    }
  }
}

Here is the code I am using to create this index

import json

import requests

schema = {
    "mappings": {
        "payment": {
            "properties": {
                "timestamp": {"type": "date"},
                "base_amount": {"type": "integer"},
                "derived_key": {"type": "keyword", "fielddata": True},
                "attempts": {"type": "integer"},
                "status": {"type": "text", "fielddata": True},
                "error_code": {"type": "text", "fielddata": True}
            }
        }
    }
}

index = 'http://localhost:9200/payment_index_2016_08_21'
r = requests.put(index, data=json.dumps(schema))

print r.content

The error I get is

{"error":{"root_cause":[{"type":"mapper_parsing_exception","reason":"Mapping definition for [derived_key] has unsupported parameters: [fielddata : true]"}],"type":"mapper_parsing_exception","reason":"Failed to parse mapping [payment]: Mapping definition for [derived_key] has unsupported parameters: [fielddata : true]","caused_by":{"type":"mapper_parsing_exception","reason":"Mapping definition for [derived_key] has unsupported parameters: [fielddata : true]"}},"status":400}

I don't understand why the fielddata = true is causing an issue, since I see it's allowed here https://www.elastic.co/guide/en/elasticsearch/reference/current/fielddata.html. Any clue what the issue behind this is?

0

1 Answer 1

3

You don't need to enable fielddata on keyword fields. you can do aggregations on keyword fields.

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

4 Comments

Yup it works. So what you mean is that on keywords, you can perform aggregation by default and we don't need to enable that by fielddata = true (since it's already enabled) and the purpose of fielddata is to perform aggreations, correct?
Yes are are correct. some tasks like aggregations, sorting, ... need different requirements than search and text fields are mean to be searched in by default an other fields can be aggregated/sorted on by default. So if you need sorting/aggregation/... on text fields you should enable fielddata for them which could be memory expensive!
Done. Just changed it to text instead of keyword and it works. Thanks!
Good. You can take a look at https://www.elastic.co/guide/en/elasticsearch/reference/current/fielddata.html for more detailed information about fielddata.

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.