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正在放棄這個領域。但我不確定。
如果您有任何想法,我會感激!