如何有条件地向文档添加新字段?
ElasticSearch中的当前数据
"_index": "test",
"_type": "logs",
"_id": "AWDgIKFCvg3odC71dRbc",
"_score": 0.09685399,
"_source": {
"HighTH": 120000,
"@timestamp": "2018-01-10T12:52:02.684Z",
"Cust": 16926,
"areaCode": 123
"application": "myapps",
"@version": "1",
"host": "localhost",
"Run_date": "2018-01-03T16:00:00.000Z",
"LowTH": 10000,
"message": "04-JAN-2018,MN,16926,206472,15785,120000,10000",
"Trans": 206472,
"Cntry_code": "NO",
"Trans_GPS": 15785
}
仅当“客户” = 16926和“ areaCode” = 123时,我才需要在数据中添加字段“ gpsStrength”:209845。
所需结果必须为
"_index": "test",
"_type": "logs",
"_id": "AWDgIKFCvg3odC71dRbc",
"_score": 0.09685399,
"_source": {
"HighTH": 120000,
"@timestamp": "2018-01-10T12:52:02.684Z",
"Cust": 16926,
"areaCode": 123
"application": "myapps",
"@version": "1",
"host": "localhost",
"Run_date": "2018-01-03T16:00:00.000Z",
"LowTH": 10000,
"message": "04-JAN-2018,MN,16926,206472,15785,120000,10000",
"Trans": 206472,
"Cntry_code": "NO",
"Trans_GPS": 15785,
"gpsStrength": 209845
}
我尝试使用索引类型和ID来更新数据
> POST test/logs/AWDgIKFCvg3odC71dRbc/_update?pretty { "doc": {
> "gpsStrength" : "209845" }
但必须根据_source值进行查询
我使用了动态映射