我正在尝试在ElasticSearch中进行一些测试。我能够根据需要填充所有内容,但是每当我尝试放置项目的默认模板然后插入时,数据都不会在索引中摄取(http调用虽然成功(。
经过检查,我意识到即使使用 elasticSearch 的默认模板,我也无法插入简单的文档。 例如,从 ES 的文档插入模板:
PUT _template/template_1
{
"index_patterns": ["te*", "bar*"],
"settings": {
"number_of_shards": 1
},
"mappings": {
"_source": {
"enabled": false
},
"properties": {
"host_name": {
"type": "keyword"
},
"created_at": {
"type": "date",
"format": "EEE MMM dd HH:mm:ss Z yyyy"
}
}
}
}
然后在index = "bark"
中插入一个文档
PUT http://localhost:9200/bark/_doc/11232 HTTP/1.1
User-Agent: Fiddler
Host: localhost:9200
Content-Length: 21
Content-Type: application/json
{"host_name": "generic_name"}
在索引中添加一个文档,但没有有关host_name
的数据。 只需将索引名称更改为此模板不适用的名称(如index = dark
(,即可添加一个包含有关host_name
数据的文档。 显示用于复制的索引数据:
(index=bark
时(
{"took":2,"timed_out":false,"_shards":{"total":1,"successful":1,"skipped":0,"failed":0},"hits":{"total":{"value":1,"relation":"eq"},"max_score":1.0,"hits":[{"_index":"bark","_type":"_doc","_id":"11232","_score":1.0}]}}
(当index=dark
(
{"took":6,"timed_out":false,"_shards":{"total":1,"successful":1,"skipped":0,"failed":0},"hits":{"total":{"value":1,"relation":"eq"},"max_score":1.0,"hits":[{"_index":"dark","_type":"_doc","_id":"11232","_score":1.0,"_source":{"host_name":"generic_name"}}]}}
注意到前者中没有_source":{"host_name":"generic_name"}
字段吗?
对此可以做些什么?如果有人遇到此问题或知道修复方法,请提供帮助。
您需要将其从映射中删除
"_source": {
"enabled": false
},
此设置的效果是源文档不存储在_source
字段中。这可能不是你想要的。