繁体   English   中英

ElasticSearch在Java索引中删除了一个字段

[英]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属性。 因此,插入具有相同idversionname经过修改的文档将导致版本冲突。 命令行中的PUT是有效的,因为它是一个新文档。 它与Java无关。

我应该使用update API进行部分更新。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM