[英]Create a id(key) baed on JSON document for Elasticsearch
At my Java application I need to store a JSON document at ElasticSearch. 在我的Java应用程序中,我需要在ElasticSearch上存储一个JSON文档。 I want to prevent a duplication of the documents in ES so I'm going to calculate some kind of id(key) based on JSON object/string and use it as own id for this document when indexing at ES.
我想防止ES中的文档重复,因此我将基于JSON对象/字符串计算某种id(key),并在ES进行索引时将其用作此文档的自己的id。 Unfortunately I don't have any candidates for a natural key inside of this JSON, so should take into account the whole JSON object/string for this key generation.
不幸的是,我在此JSON中没有自然键的任何候选者,因此在生成此键时应考虑整个JSON对象/字符串。
This is an example of JSON document: 这是JSON文档的示例:
{
"filterQueries":[
{
"type":"LessOrEqualQuery",
"characteristicId":630,
"value":799621200000,
"operator":"<="
}
],
"sortCriteriaIds":[
566,
572
],
"sortWeightCriteriaDirection":"DESC",
"sortTotalVotesCriteriaDirection":null,
"sortCriteriaCoefficients":{
"572":20.0
},
"sortCharacteristicId":631,
"sortCharacteristicDirection":"DESC",
"sortDecisionPropertyName":"createDate",
"sortDecisionPropertyDirection":"DESC",
"excludeChildDecisionIds":null,
"includeChildDecisionIds":null,
"pageNumber":0,
"pageSize":100
}
What is the best way to calculate this key based on JSON object/string in Java ? 在Java中基于JSON对象/字符串计算此密钥的最佳方法是什么? Performance is a very important criterion to me there.
绩效对我而言是一个非常重要的标准。
If speed concerns very much. 如果速度很受关注。 You can use XOR operation (almost CRC32 for any size).
您可以使用XOR操作(任意大小几乎为CRC32)。
Pseudocode: 伪代码:
input_string = Stringify(json)
result = 0;
for(each chunk of size K from input_string){
result = result XOR chunk;
}
return result
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.