0
我最近遇到了Java中使用ElasticSearch索引的问题。当从序列化的json字节数组中向ElasticSearch写入记录时,其中一个字段丢失或丢失。ElasticSearch在使用Java编制索引时删除了一个字段
漂亮印刷byte[] content
例如:
{
"created_at": 1468390585000,
"name": "Lucy",
"id": 123,
"message": "Hi how are you",
"thread_id": 456,
"user_id": 789
}
Java的索引呼叫:
IndexRequest indexRequest = new IndexRequest(INDEX, TYPE, data.getId().toString())
.source(content)
.versionType(VersionType.EXTERNAL)
.version(data.getCreatedAt().getTime());
在索引,所有字段存在于结果除了name
:
GET /my_index/post/123
{
"_index": "my_index",
"_type": "post",
"_id": "123",
"_version": 1468390585000,
"found": true,
"_source": {
"id": 123,
"user_id": 456,
"created_at": 1468390585000,
"message": "Hi how are you",
"thread_id": 789
}
}
name
是我新创建的新领域。它存在于映射中:
{
"my_index":{
"mappings":{
"post":{
"properties":{
"created_at":{
"type":"long"
},
"name":{
"type":"string"
},
"id":{
"type":"long"
},
"message":{
"type":"string",
"analyzer":"english_text"
},
"thread_id":{
"type":"long"
},
"user_id":{
"type":"long"
}
}
}
}
}
}
其他字段是在创建post
类型时创建的。
我怀疑在Java API中编写/索引数据时存在某种过滤。我可以在命令行中输入PUT
相同的json,并在结果中看到name
。似乎只有Java API正在放弃这个领域。但我不确定。
如果您有任何想法,我会感激!