elasticsearch中的python3.x布尔转换

k0pti3hp  于 2021-06-14  发布在  ElasticSearch
关注(0)|答案(1)|浏览(374)

我试图在es中创建一个索引,指定如下所示的请求主体。请在下面找到我的代码:

import time
from elasticsearch import Elasticsearch
from elasticsearch import helpers

ELASTICSEARCH_HOST = "localhost"
ELASTICSEARCH_PORT = 9200
ELASTICSEARCH_INDEX_NAME = "phonetic_index"

es = Elasticsearch([{'host': ELASTICSEARCH_HOST, 'port': 
ELASTICSEARCH_PORT}])

if es.indices.exists(ELASTICSEARCH_INDEX_NAME):
  print("Deleting '%s' index..." % (ELASTICSEARCH_INDEX_NAME))
  res = es.indices.delete(index = ELASTICSEARCH_INDEX_NAME)
  print(" response: '%s'" % (res))

print("Creating '%s' index..." % (ELASTICSEARCH_INDEX_NAME))
request_body = {
  "settings": {
    "analysis": {
      "filter": {
        "haasephonetik": {
          "type": "phonetic",
          "encoder": "haasephonetik"
        }
      },
       "analyzer": {
        "haasephonetik": {
          "tokenizer": "standard",
          "filter": "haasephonetik"
         }
       }
    }
   },
   "mappings": {
    "type": {
       "properties": {
        "text": {
           "type": "text",
          "index": "not_analyzed",
           "fields": {
            "phonetic": {
               "type": "text",
              "analyzer": "haasephonetik"
            }
           }
        }
       }
    }
   }
}

res = es.indices.create(index = ELASTICSEARCH_INDEX_NAME, body 
request_body)
print(" response: '%s'" % (res))

问题是,我有以下错误,我不能将索引转换为布尔值。所以我不明白为什么下面有这样的信息。有人已经犯了这个错误,因为这对我来说并不明显

PUT http://localhost:9200/phonetic_index [status:400 
request:0.034s]
------------------------------------------------------------------ 
---------
RequestError                              Traceback (most recent 
call last)
<ipython-input-23-33349743a94c> in <module>()
----> 1 es.indices.create(index = ELASTICSEARCH_INDEX_NAME, body = 
request_body)

 ~/anaconda3/lib/python3.7/site- 
packages/elasticsearch/client/utils.py in _wrapped(*args, 

**kwargs)

     74                 if p in kwargs:
     75                     params[p] = kwargs.pop(p)
---> 76             return func(*args, params=params,**kwargs)
     77         return _wrapped
     78     return _wrapper

~/anaconda3/lib/python3.7/site- 
packages/elasticsearch/client/indices.py in create(self, index, 
body, params)
     86             raise ValueError("Empty value passed for a 
required argument 'index'.")
     87         return self.transport.perform_request('PUT', 
 _make_path(index),
 ---> 88             params=params, body=body)
     89 
     90     @query_params('allow_no_indices', 'expand_wildcards', 
'flat_settings',

~/anaconda3/lib/python3.7/site-packages/elasticsearch/transport.py 
in perform_request(self, method, url, headers, params, body)
    316                 delay = 2**attempt - 1
    317                 time.sleep(delay)
--> 318                 status, headers_response, data = 
connection.perform_request(method, url, params, body, 
headers=headers, ignore=ignore, timeout=timeout)
    319 
    320             except TransportError as e:

~/anaconda3/lib/python3.7/site- 
packages/elasticsearch/connection/http_urllib3.py in 
perform_request(self, method, url, params, body, timeout, ignore, 
headers)
    184         if not (200 <= response.status < 300) and 
response.status not in ignore:
    185             self.log_request_fail(method, full_url, url, 
body, duration, response.status, raw_data)
   --> 186             self._raise_error(response.status, raw_data)
       187 
       188         self.log_request_success(method, full_url, url, 
    body, response.status,

~/anaconda3/lib/python3.7/site- 
packages/elasticsearch/connection/base.py in _raise_error(self, 
status_code, raw_data)
    123             logger.warning('Undecodable raw error response 
from server: %s', err)
    124 
--> 125         raise HTTP_EXCEPTIONS.get(status_code, 
TransportError)(status_code, error_message, additional_info)
    126 
    127 

RequestError: RequestError(400, 'mapper_parsing_exception', 
'Failed to parse mapping [type]: Could not convert [text.index] to 
boolean')

顺便说一句,谢谢你的帮助。
当做,
比利

f4t66c6m

f4t66c6m1#

请将Map下的属性块更新到以下位置:

{
  "text": {
    "type": "keyword",
    "fields": {
      "phonetic": {
        "type": "text",
        "analyzer": "haasephonetik"
      }
    }
  }
}

我已删除: "index": "not_analyzed" 并改变了 typetext 字段到 keyword . 如果你想要 string 待处理字段 not_analyzed 将其类型设置为 keyword .

相关问题