我必须使用_id作为消息中多个字段的组合来增加弹性搜索索引中的批量记录。我可以这样做吗?如果可以做到的话,请给我一个相同的示例json。 问候
一个示例_id字段,我正在寻找类似下面的内容
{
"_index": "kpi_aggr",
"_type": "KPIBackChannel",
"_id": "<<<combination of name , period_type>>>",
"_score": 1,
"_source": {
"name": "kpi-v1",
"period_type": "w",
"country": "AL",
"pg_name": "DENTAL CARE",
"panel_type": "retail",
"number_of_records_with_proposal": 10000,
"number_of_proposals": 80000,
"overall_number_of_records": 2000,
"@timestamp": 1442162810
}
}
答案 0 :(得分:0)
自然地,您可以在调用Index API的过程中指定自己的Elasticsearch文档ID:
PUT kpi_aggr/KPIBackChannel/kpi-v1,w
{
"name": "kpi-v1",
"period_type": "w",
"country": "AL",
"pg_name": "DENTAL CARE",
"panel_type": "retail",
"number_of_records_with_proposal": 10000,
"number_of_proposals": 80000,
"overall_number_of_records": 2000,
"@timestamp": 1442162810
}
您也可以在_bulk
API call期间这样做:
POST _bulk
{ "index" : { "_index" : "kpi_aggr", "_type" : "KPIBackChannel", "_id" : "kpi-v1,w" } }
{"name":"kpi-v1","period_type":"w","country":"AL","pg_name":"DENTAL CARE","panel_type":"retail","number_of_records_with_proposal":10000,"number_of_proposals":80000,"overall_number_of_records":2000,"@timestamp":1442162810}
请注意,Elasticsearch将用新版本替换文档。
如果您在空索引上执行这两个查询,然后按文档ID查询:
GET kpi_aggr/KPIBackChannel/kpi-v1,w
将为您提供以下内容:
{
"_index": "kpi_aggr",
"_type": "KPIBackChannel",
"_id": "kpi-v1,w",
"_version": 2,
"found": true,
"_source": {
"name": "kpi-v1",
"period_type": "w",
"country": "AL",
"pg_name": "DENTAL CARE",
"panel_type": "retail",
"number_of_records_with_proposal": 10000,
"number_of_proposals": 80000,
"overall_number_of_records": 2000,
"@timestamp": 1442162810
}
}
通知"_version": 2
,在我们的情况下,该通知指示文档已被索引两次,因此执行了“ upsert”(但通常应用于Optimistic Concurrency Control)。
希望有帮助!