Here is an enrich processar example.
On caveat for this strategy is that you should always index car documents first and execute the enrich policy before you index the driver.
PUT /test_driver/
{
"mappings":{
"properties": {
"driverId":{"type":"keyword"},
"name":{"type":"keyword"},
"country":{"type":"keyword"},
"countryId":{"type":"keyword"}
}
}
}
PUT /test_car/
{
"mappings": {
"properties": {
"carId":{"type": "keyword"},
"model":{"type": "keyword"},
"modelId":{"type": "keyword"},
"ownerId":{"type": "keyword"}
}
}
}
POST /test_car/_bulk
{"index":{}}
{"carId":"car001","model":"model001","ownerId":"001"}
{"index":{}}
{"carId":"002","model":"model002","ownerId":"001"}
PUT /_enrich/policy/test_car_policy
{
"match":{
"indices":"test_car",
"match_field":"ownerId",
"enrich_fields":["carId","model","modelId"]
}
}
PUT /_enrich/policy/test_car_policy/_execute
PUT /_ingest/pipeline/test_car_enrich
{
"description": "car enrich",
"processors": [
{
"enrich": {
"policy_name": "test_car_policy",
"field":"driverId",
"target_field":"car",
"max_matches":"128"
}
}
]
}
POST /_ingest/pipeline/test_car_enrich/_simulate
{
"docs":[
{
"_index":"test_driver",
"_source":{
"driverId":"001"
}
}
]
}
PUT /test_driver/_settings
{
"index":{
"default_pipeline": "test_car_enrich"
}
}
GET /test_driver
POST /test_driver/_bulk
{"index":{}}
{"driverId":"001","name":"foo"}
{"index":{}}
{"driverId":"002","name":"baa"}
GET /test_driver/_search
{
"hits" : {
"hits" : [
{
"_index" : "test_driver",
"_type" : "_doc",
"_id" : "pvQQfH4Bf0nakUP8c2Xp",
"_score" : 1.0,
"_source" : {
"driverId" : "001",
"car" : [
{
"model" : "model001",
"ownerId" : "001",
"carId" : "car001"
},
{
"model" : "model002",
"ownerId" : "001",
"carId" : "002"
}
],
"name" : "foo"
}
},
{
"_index" : "test_driver",
"_type" : "_doc",
"_id" : "p_QQfH4Bf0nakUP8c2Xp",
"_score" : 1.0,
"_source" : {
"driverId" : "002",
"name" : "baa"
}
}
]
}
}