Python Elasticsearch 创建索引映射

Python Elasticsearch create index mapping

我正在尝试使用 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

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

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