[英]How to index in elasticsearch using post request in Python?
I am facing an issue: 我面临一个问题:
RequestError(400, 'illegal_argument_exception', 'mapper [columns.analysis.abstract_stats.description.std] of different type, current_type [text], merged_type [float]')
RequestError(400,'illegal_argument_exception','不同类型的映射器[columns.analysis.abstract_stats.description.std],current_type [text],merged_type [float]')
which led me to go for a solution described here . 这导致我去寻求这里描述的解决方案。
My current code which is generating the aforementioned error is: 我当前产生上述错误的代码是:
from test_mapping import a
es = Elasticsearch([{'host': 'A.B.C.D', 'port': 9200}])
try:
es.index(index='datatables', doc_type='datatable_v1', id="pallet_d3dd6729b810bebd955708e85afc1f65c3f2685c", body=a)
except Exception as e:
print (e)
The index existed before but I have deleted it and then running the above code is still generating the above error. 该索引之前已经存在,但是我已将其删除,然后运行上面的代码仍会生成上述错误。 The variable
a
is here 变量
a
在这里
The reason for the above error is when you send data to elastic then it created dynamic field for the keys it find missing in the mapping and try to identify its type. 发生上述错误的原因是,当您将数据发送到Elastic时,它为映射中发现的键创建了动态字段,并尝试标识其类型。 Base on the data you are sending in
body
the value at columns.analysis.abstract_stats.description.std
is mapped to float
type but one of the record at key columns.analysis.abstract_stats.description.std
has value 'NaN'
which can't be mapped to a float field and hence the error. 根据您在
body
中发送的数据,将columns.analysis.abstract_stats.description.std
的值映射为float
类型,但关键columns.analysis.abstract_stats.description.std
的记录之一具有值'NaN'
,该值可以t被映射到float字段,因此会出现错误。 You need to make sure that type of fields doesn't change from one record to another. 您需要确保字段类型不会从一条记录更改为另一条记录。
Use this to load a: 使用它来加载:
import simplejson
es.index(index='datatables', doc_type = 'datatable_v1', id = "pallet_d3dd6729b810bebd955708e85afc1f65c3f2685c", body = simplejson.dumps(a, ignore_nan = True))
This should solve your problem. 这应该可以解决您的问题。 Now your application will read this value as None (which is possibly the source of this corruption) and you can easily implement your functionality
现在,您的应用程序将将此值读取为None(这可能是此损坏的根源),您可以轻松实现功能
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.