【问题标题】:Python Elasticsearch create index mappingPython Elasticsearch 创建索引映射
【发布时间】:2020-09-23 04:22:54
【问题描述】:

我正在尝试使用 elasticsearch python 创建具有自定义映射的 ES 索引,以增加每个文档中文本的大小:

mapping = {"mapping":{
           "properties":{
             "Apple":{"type":"text","ignore_above":1000},
             "Mango":{"type":"text","ignore_above":1000}
           }
          }}

创作:

from elasticsearch import Elasticsearch
es1 = Elasticsearch([{"host":"localhost","port":9200}])
es1.indices.create(index="hello",body=mapping)

错误:

RequestError: RequestError(400, 'mapper_parsing_exception', 'Mapping definition for [Apple] has unsupported parameters: [ignore_above : 10000]') 

但我查看了 elasticsearch 网站关于如何增加文本长度限制,ignore_above 是那里给出的选项。 https://www.elastic.co/guide/en/elasticsearch/reference/current/ignore-above.html

任何关于如何纠正这个问题的建议都会很棒。

【问题讨论】:

    标签: python elasticsearch elastic-stack elasticsearch-py


    【解决方案1】:

    ignore_above 设置仅适用于 keyword 类型而不是 text,因此只需将映射更改为此即可:

    mapping = {"mapping":{
           "properties":{
             "Apple":{"type":"text"},
             "Mango":{"type":"text"}
           }
          }}
    

    如果您绝对需要能够指定ignore_above,那么您需要将类型更改为keyword,如下所示:

    mapping = {"mapping":{
           "properties":{
             "Apple":{"type":"keyword","ignore_above":1000},
             "Mango":{"type":"keyword","ignore_above":1000}
           }
          }}
    

    【讨论】:

    • 但我需要将 ignore_above 更改为 1000,因为我正在尝试加载字符串值大于默认长度 256 的 pandas DF。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-15
    • 1970-01-01
    • 2017-03-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多