我正在尝试将一些这样的消息推送到 elasticsearch
id=1
list=asd,bcv mnmn,kjkj, pop asd dgf
因此,每条消息都有一个
id
字段是一个字符串,一个 list
包含字符串值列表的字段当我将它插入弹性并尝试在 kibana 中创建图表时,默认分析器会启动并拆分我的
list
由空格字符。因此,它打破了我的值(value)观。我试图为我的索引创建一个映射mapping='''
{
"test":
{
"properties": {
"DocumentID": {
"type": "string"
},
"Tags":{
"type" : "string",
"index" : "not_analyzed"
}
}
}
}'''
es = Elasticsearch([{'host': server, 'port': port}])
indexName = "testindex"
es.indices.create(index=indexName, body=mapping)
所以这应该使用我定义的映射创建索引。现在,我通过简单的方式推送消息
es.index(indexName, docType, messageBody)
但即使是现在,Kibana 也打破了我的值(value)观!为什么没有应用映射?
当我这样做的时候
GET /testindex/_mapping/test
我明白了
{
"testindex": {
"mappings": {
"test": {
"properties": {
"DocumentID": {
"type": "string"
},
"Tags": {
"type": "string"
}
}
}
}
}
}
为什么映射发生了变化?当我这样做时如何指定映射类型
es.index()
最佳答案
你非常亲近。您需要提供根 mappings
创建索引时的对象,使用 _mapping
时不需要它终点,这就是原因put_mapping
工作和create
没有。您可以在 api 中看到.
mapping = '''
{
"mappings": {
"test": {
"properties": {
"DocumentID": {
"type": "string"
},
"Tags": {
"type": "string",
"index": "not_analyzed"
}
}
}
}
}
'''
现在这将按预期工作
es.indices.create(index=indexName, body=mapping)
希望这可以帮助
关于python-2.7 - Elasticsearch : es. index() 消息推送时改变映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35137022/