弹性搜索无效的版本格式类型和invalid_argument_exception

时间:2019-04-12 05:22:12

标签: python-3.x elasticsearch

python代码

request_body = {
    "settings": {
        "index" : {"number_of_shards" : 1, "number_of_replicas" : 0 
      }},
    "mappings": {
        "document": {"dynamic": "strict","properties": {
                "doc_name": { "type": "text"},                   
                "doc_location" : { "type" : "text" },
                "doc_keywords": { "type": "nested","properties": {
                        "dynamic": "true","tag": {"type": "text"},
                        "score": {"type": "text"}
                    } } }} }}
 es_object.indices.create(index=index_name, ignore=400,body=request_body)


def store_document(es_object, index_name, doc_name, doc_location, result_dictionary):
    keyword_nested_obj = []
    for key, value in result_dictionary.items():
        keyword_nested_obj.append({"tag":key, "score":value})
    doc = {
        "doc_name" : doc_name,
        "doc_s3_location" : doc_s3_location,
        "doc_keywords" : keyword_nested_obj
    }
    es_object.index(index = index_name, doc_type = 'document', body=doc)

#sample data storage
doc_location = "link"
doc_name = "00000020"
result_dictionary = {}
result_dictionary['Duplex and color Doppler'] = 0.7
result_dictionary['Compressibility'] = 0.6
result_dictionary['augmentation'] = 0.7

# Call the function
store_document(es_object, "documentrepository", doc_name, doc_location,
 result_dictionary)

下面的搜索会引发错误

json_q = json.dumps({"query": { "match_all": {}}})
res = es_object.search(index="documentrepository", doc_type="document", 
body=json_q)

错误:

RequestError: RequestError(400, 'illegal_argument_exception', 'invalid 
version format: {}}}GET /DOCUMENTREPOSITORY/DOCUMENT/_SEARCH HTTP/1.1')

Elasticsearch服务器版本6.7.1也是python驱动程序> 6。 同样,以上代码片段也可以与Elastic-search 5.6.8和python driver 5.5.3完美配合 有线索吗?

1 个答案:

答案 0 :(得分:0)

对于社区发布答案,在一开始,我以为这可能是版本不匹配的问题。基本上,在AWS配置中,传输端口(默认为9300)在另一个ec2实例上关闭,该实例在安装6.7.1时会丢失。

install elasticsearch on aws

Elastic search guide