Elasticsearch python从json创建别名

问题描述 投票:0回答:1

elasticsearch的新手

[尝试使用elasticsearch-py api从json初始化索引;使用这个简单的json文件只是了解它的工作方式

{
  "index": "index_name",
  "body": {
    "aliases": {
      "actions": [
        { "add": { "index": "index_name",  "alias": "alias1" } }
      ]
    },
    "mappings": {
      "properties": {
        "age":    { "type": "integer" },
        "email":  { "type": "keyword"  },
        "name":   { "type": "text"  }
      }
    },
    "settings": {
      "number_of_shards":   2,
      "number_of_replicas": 1,
      "index.refresh_interval": "120s"
    }
  }
}

((读取json文件,解析出indexbody),然后是重要的python部分es.indices.create(index=index, body=body)

但是我遇到错误:

elasticsearch.exceptions.TransportError: TransportError(500, 'null_pointer_exception', 'fieldName cannot be null')

我从ES文档中提取了映射和别名示例。 python与另一个没有别名的json文件一起使用。当我从该文件中删除别名时,出现另一个错误,提示不支持的映射参数,因此我不确定问题出在哪里,但想先解决别名问题

python json elasticsearch
1个回答
0
投票

正如source codeelasticsearch-py所说,bodyindices.create自变量不能包含任何别名:

正文:索引的配置(settingsmappings

话虽这么说,该库中有other methods使您可以创建别名。

© www.soinside.com 2019 - 2024. All rights reserved.