[英]ElasticSearch drops a field in indexing with Java
我最近在Java中用ElasticSearch索引遇到了这个问题。 当从序列化的json字节数组将记录写入ElasticSearch时,字段之一丢失或丢失。
漂亮打印的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删除了该字段。 但我不确定。
如果您有任何想法,我将不胜感激!
事实证明,现有文档没有新的name
属性。 因此,插入具有相同id
和version
且name
经过修改的文档将导致版本冲突。 命令行中的PUT
是有效的,因为它是一个新文档。 它与Java无关。
我应该使用update
API进行部分更新。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.