簡體   English   中英

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM