索引映射时不支持Elasticsearch fielddata

时间:2017-06-05 15:52:45

标签: python elasticsearch schema elasticsearch-indices

我试图通过Python在Elasticsearch中创建索引。我部署了一个本地ES实例,查询运行正常。但是,我有一个架构。这是:

{
  "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}
      }
    }
  }
}

以下是我用来创建此索引的代码

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

我得到的错误是

  

{"错误" {" ROOT_CAUSE":[{"类型":" mapper_parsing_exception""理由&#34 ;:"映射   [derived_key]的定义有不支持的参数:[fielddata:   是]"}],"输入":" mapper_parsing_exception","原因":"无法解析   mapping [payment]:[derived_key]的映射定义   不支持的参数:[fielddata:   真]"" caused_by" {"类型":" mapper_parsing_exception""理由":"映射   [derived_key]的定义有不支持的参数:[fielddata:   真]"}},"状态" 400}

我不明白fielddata = true导致问题的原因,因为我认为https://www.elastic.co/guide/en/elasticsearch/reference/current/fielddata.html允许{{1}}。有什么线索背后的问题是什么?

1 个答案:

答案 0 :(得分:1)

您不需要在关键字字段上启用fielddata。你可以对关键字字段进行聚合。