Elasticsearch python从json创建别名
elasticsearch非常新 尝试使用elasticsearch py api从json初始化索引;使用这个简单的json文件来了解它是如何工作的Elasticsearch python从json创建别名,python,json,
elasticsearch,Python,Json,
elasticsearch,elasticsearch非常新 尝试使用elasticsearch py api从json初始化索引;使用这个简单的json文件来了解它是如何工作的 { "index": "index_name", "body": { "aliases": { "actions": [ { "add": { "index": "index_name", "alias": "alias1" } } ] }, "mappings": {
{
"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文件,解析出索引
和正文
),然后是重要的python部分
es.index.create(index=index,body=body)
但我有一个错误:
elasticsearch.exceptions.TransportError: TransportError(500, 'null_pointer_exception', 'fieldName cannot be null')
我从ES文档中提取了映射和别名示例。python使用不同的json文件,该文件中没有别名。当我从这个文件中删除别名时,我得到了另一个关于不受支持的映射参数的错误,因此我不确定问题在哪里,但我想首先解决别名问题,正如elasticsearch py
的说明,索引的body
参数。create
不能包含任何别名:
正文:索引的配置(设置
和映射
)
话虽如此,该库中有一些可以让您创建别名的工具。正如公认的答案所说,我没有阅读文档。发布最终为我工作的内容以记录
config.json
文件如下所示
"index": "index_1",
"aliases": ["alias1", "alias2"],
"body": {
"mappings": {...},
"settings": {...}
}
还有蟒蛇
_json = json.load(file)
index = _json['index']
aliases = _json['aliases']
body = _json['body']
es.indices.create(index=index, body=body)
if len(aliases) > 0:
for alias in aliases:
es.indices.put_alias(index=index, name=alias)