【问题标题】:Elasticsearch fielddata unsupported while index mapping索引映射时不支持 Elasticsearch 字段数据
【发布时间】:2017-11-06 10:53:11
【问题描述】:

我正在尝试通过 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

我得到的错误是

{"error":{"root_cause":[{"type":"mapper_parsing_exception","re​​ason":"映射 [derived_key] 的定义具有不受支持的参数: [fielddata : true]"}],"type":"mapper_parsing_exception","re​​ason":"解析失败 mapping [payment]: [derived_key] 的映射定义有 不支持的参数:[fielddata: true]","caused_by":{"type":"mapper_parsing_exception","re​​ason":"映射 [derived_key] 的定义具有不受支持的参数: [fielddata : true]"}},"status":400}

我不明白为什么fielddata = true 会导致问题,因为我看到https://www.elastic.co/guide/en/elasticsearch/reference/current/fielddata.html 在这里是允许的。知道这背后的问题是什么吗?

【问题讨论】:

    标签: python elasticsearch schema elasticsearch-indices


    【解决方案1】:

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

    【讨论】:

    • 是的,它有效。所以你的意思是,在关键字上,你可以默认执行聚合,我们不需要通过 fielddata = true 来启用它(因为它已经启用)并且 fielddata 的目的是执行聚合,对吗?
    • 是的都是正确的。 aggregationssorting、...等一些任务需要与 search 不同的要求,并且默认情况下要搜索文本字段,默认情况下可以对其他字段进行聚合/排序。因此,如果您需要对文本字段进行排序/聚合/...,您应该为它们启用 fielddata,这可能会占用大量内存!
    • 完成。只需将其更改为文本而不是关键字即可。谢谢!
    • 好。您可以查看https://www.elastic.co/guide/en/elasticsearch/reference/current/fielddata.html,了解有关 fielddata 的更多详细信息。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-25
    • 2017-01-10
    • 1970-01-01
    • 1970-01-01
    • 2015-11-03
    相关资源
    最近更新 更多