我试图在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')
顺便说一句,谢谢您的帮助。
此致
比利
答案 0 :(得分:0)
请在下面的映射下更新属性块:
{
"text": {
"type": "keyword",
"fields": {
"phonetic": {
"type": "text",
"analyzer": "haasephonetik"
}
}
}
}
我已删除:"index": "not_analyzed"
,并将type
的{{1}}字段更改为text
。在es 6.x中,如果希望将keyword
字段设为string
,请将其类型设置为not_analyzed
。