简体   繁体   English

弹性搜索中使用_id作为文档标识符

[英]Use of _id for document identifier in elastic search

I have a document with _id as a parameter. 我有一个以_id为参数的文档。 I have the below JSON 我有以下JSON

{  
   "_id":{  
      "$oid":"52af48b5d55148fa0c199643"
   },
   "email":"example.ex@example.com"
}

Corresponding Java class: 对应的Java类:

@Document(indexName = "Test")
public class Test {

  @Id
  @ObjectId
  private String _id;

  private String email;
}

The conversion of json object is successful but there is a problem in saving the data to elastic search. json对象的转换成功,但是将数据保存到弹性搜索中存在问题。

org.elasticsearch.index.mapper.MapperParsingException: Field [_id] is a metadata field and cannot be added inside a document. Use the index API request parameters

I have seen some references and came to a conclusion that i cannot use _id.. But am looking for a way to use a JsonProperty but it also does not work as i guess ObjectId uses JsonProperty internally. 我已经看到了一些参考资料并得出了我不能使用_id的结论。但是我正在寻找一种使用JsonProperty的方法,但是它也无法正常工作,因为我猜想ObjectId在内部使用了JsonProperty。

Kindly provide suggestions 请提供建议

Like the error message say, you can't use field with name _id inside the document. 就像错误消息说的那样,您不能在文档中使用名称为_id的字段。

To fix that use "replace all"(or function like that that replace substring in other substring) function, and replace all "_id" occurrence with "id" 要解决此问题,请使用“全部替换”(或在其他子字符串中替换子字符串的函数),然后将所有出现的“ _id”替换为“ id”

Just use as following 只需如下使用

{  
     "_id":"52af48b5d55148fa0c199643",
      "email":"example.ex@example.com"
}

And remove @ObjectId 并删除@ObjectId

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

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