Hi @Hendrik_Muhs ,
The above suggested code is working like a charm. Thanks for the same.
(1) If I want to apply the transform on single index then will the below code work for me:
POST /_transform/_preview?pretty
{
"id": "index_compare",
"source": {
"index": [
**"compare_pim_index"**
],
"query": {
"match_all": {}
}
},
"dest": {
"index": "compare"
},
"pivot": {
"group_by": {
"unique-id": {
"terms": {
"field": "IP.keyword"
}
}
},
"aggregations": {
"compare": {
"scripted_metric": {
"map_script": "state.doc = new HashMap(params['_source'])",
"combine_script": "return state",
"reduce_script": """
if (states.size() != 2) {
return "count_mismatch"
}
return "match"
"""
}
}
}
}
}
(2) And If instead of comparing the same field name document , can I compare two document with the two different field name like some document in a index will have IP1.keyword and some will have IP2.keyword then will the below code work:
POST /_transform/_preview?pretty
{
"id": "index_compare",
"source": {
"index": [
"compare_pim_index"
],
"query": {
"match_all": {}
}
},
"dest": {
"index": "compare"
},
"pivot": {
"group_by": {
"unique-id": {
"terms": {
**"field": "IP1.keyword",**
** "field1":"IP2.keyword"**
}
}
},
"aggregations": {
"compare": {
"scripted_metric": {
"map_script": "state.doc = new HashMap(params['_source'])",
"combine_script": "return state",
"reduce_script": """
if (states.size() != 2) {
return "count_mismatch"
}
return "match"
"""
}
}
}
}
}