我正试图在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
领域。这可能不是你想要的。