仅将少量数据传递到JSON.parse()到Elasticsearch中
[这里,我只需要允许少量数据来自JSON和Elasticsearch中的索引。那么,什么是完美的方法,而不是分别删除呢?
var elasticData= JSON.parse(result.body);
elasticData = elasticData.res;
elasticData["id"] = elasticData._id;
delete elasticData["__v"];
delete elasticData["_id"];
delete elasticData["addressee"];
delete elasticData["abbreviation"];
delete elasticData["care_of"];
delete elasticData["address_1"];
delete elasticData["address_2"];
delete elasticData["company_id_legacy"];
elasticSearch_common.createCompanyIndex(elasticData);
例如:我只需要传递("name","id","address")
,其余的我就不想传递。但是同一JSON中还有很多其他数据。
{
"userId":"34234234234gjgjg894734g",
"company":{
"id" : "21",
"addressee" : {
"addressee" : "EXAMPLE",
"title_name" : "",
"salutation" : "Dear:",
"comments" : "",
"email" : "[email protected]",
"phone" : "",
"fax" : "",
"extention_group" : "",
"ext" : ""
},
"abbreviation" : "",
"care_of" : "",
"address_1" : "2",
"address_2" : "",
"address_3" : "",
"state" : "CA",
"zip" : "90024",
"is_deleted" : false,
"company_code" : "sdas",
"parent_company" : null,
"name" : "NIOE",
"createdBy" : "Dat",
"modifiedBy" : "Dat",
"createdDate" : "2019-08-22T19:10:50.000+0000",
"modifiedDate" : "2019-08-22T19:10:50.000+0000",
}
这是实际的JSON,下面我希望将其作为Elasticsearch索引数据进行推送。
{ name: 'NIOE',
id: '21' }
回答如下:如何将其列入白名单?
// raw data you get from wherever
const elasticData = JSON.parse(result.body);
// object to index into ES
const toIndex = {};
// whitelist of fields to index
["name", "id", "address"].forEach(field => {
toIndex[field] = elasticDatapany ? elasticDatapany[field] : null;
});
// assert: toIndex now contains only the fields you want to index
elasticSearch_common.createCompanyIndex(toIndex);
仅将少量数据传递到JSON.parse()到Elasticsearch中
[这里,我只需要允许少量数据来自JSON和Elasticsearch中的索引。那么,什么是完美的方法,而不是分别删除呢?
var elasticData= JSON.parse(result.body);
elasticData = elasticData.res;
elasticData["id"] = elasticData._id;
delete elasticData["__v"];
delete elasticData["_id"];
delete elasticData["addressee"];
delete elasticData["abbreviation"];
delete elasticData["care_of"];
delete elasticData["address_1"];
delete elasticData["address_2"];
delete elasticData["company_id_legacy"];
elasticSearch_common.createCompanyIndex(elasticData);
例如:我只需要传递("name","id","address")
,其余的我就不想传递。但是同一JSON中还有很多其他数据。
{
"userId":"34234234234gjgjg894734g",
"company":{
"id" : "21",
"addressee" : {
"addressee" : "EXAMPLE",
"title_name" : "",
"salutation" : "Dear:",
"comments" : "",
"email" : "[email protected]",
"phone" : "",
"fax" : "",
"extention_group" : "",
"ext" : ""
},
"abbreviation" : "",
"care_of" : "",
"address_1" : "2",
"address_2" : "",
"address_3" : "",
"state" : "CA",
"zip" : "90024",
"is_deleted" : false,
"company_code" : "sdas",
"parent_company" : null,
"name" : "NIOE",
"createdBy" : "Dat",
"modifiedBy" : "Dat",
"createdDate" : "2019-08-22T19:10:50.000+0000",
"modifiedDate" : "2019-08-22T19:10:50.000+0000",
}
这是实际的JSON,下面我希望将其作为Elasticsearch索引数据进行推送。
{ name: 'NIOE',
id: '21' }
回答如下:如何将其列入白名单?
// raw data you get from wherever
const elasticData = JSON.parse(result.body);
// object to index into ES
const toIndex = {};
// whitelist of fields to index
["name", "id", "address"].forEach(field => {
toIndex[field] = elasticDatapany ? elasticDatapany[field] : null;
});
// assert: toIndex now contains only the fields you want to index
elasticSearch_common.createCompanyIndex(toIndex);