Watcher chain input, matching result set not found in action results

Hi, I am able to successfully execute the watcher which compares the field value in two different indices. However, I am not able to see the matching result. what I get is only first and second input values. I want to see only the matching documents, The output is as follows Please help.

"input": {
"chain": {
"inputs": [
{
"first": {
"search": {
"request": {
"search_type": "query_then_fetch",
"indices": [
"test"
],
"rest_total_hits_as_int": true,
"body": {
"query": {
"match_all": {}
}
{
"second": {
"search": {
"request": {
"search_type": "query_then_fetch",
"indices": [
"test123"
],
"
"condition": {
"script": {
"source": "def second_results = ctx.payload.second.hits.hits.stream().map(hit->hit._source.id).collect(Collectors.toList()); return ctx.payload.first.hits.hits.stream().map(hit -> hit._source.id).filter(p->second_results.contains(p)).collect(Collectors.toList()).size() > 0;",
"lang": "painless"
}
},

"result": {
"input": {
"type": "chain",
"status": "success",
"payload": {
"first": {
"hits": {
"hits": [
{
"_index": "test",
"_type": "_doc",
"_source": {
"name": "raju",
"id": 1
},
"_id": "0XA0SW0Bvfhb-n5H1IFL",
"_score": 1
},
{
"_index": "test",
"_type": "_doc",
"_source": {
"name": "rama",
"id": 2
},
"_id": "0nA1SW0Bvfhb-n5HF5op",
"_score": 1
}
],
"total": 2,
"max_score": 1
},
"took": 1,
"timed_out": false
},
"second": {
"hits": {
"hits": [
{
"_index": "test123",
"_type": "_doc",
"_source": {
"name": "teju",
"id": 1
},
"_id": "AnFDSW0Bvfhb-n5HmM1w",
"_score": 1
},
{
"_index": "test123",
"_type": "_doc",
"_source": {
"name": "teju",
"id": 1
},
"_id": "k00QSm0Bvfhb-n5H4XUu",
"_score": 1
},
{
"_index": "test123",
"_type": "_doc",
"_source": {
"name": "mast",
"id": 4
},
"_id": "lLtRUm0Bvfhb-n5HEYiF",
"_score": 1
}
],
"total": 3,
"max_score": 1
},
"chain": {
"first": {
"type": "search",
"status": "success",
"payload": {
"_shards": {
"total": 1,
"failed": 0,
"successful": 1,
"skipped": 0
},
"hits": {
"hits": [
{
"_index": "test",
"_type": "_doc",
"_source": {
"name": "raju",
"id": 1
},
"_id": "0XA0SW0Bvfhb-n5H1IFL",
"_score": 1
},
{
"_index": "test",
"_type": "_doc",
"_source": {
"name": "rama",
"id": 2
},
"_id": "0nA1SW0Bvfhb-n5HF5op",
"_score": 1
}
],
"total": 2,
"max_score": 1
},
"took": 1,
"timed_out": false
},
"search": {
"request": {
"search_type": "query_then_fetch",
"indices": [
"test"
],
"rest_total_hits_as_int": true,
"body": {
"query": {
"match_all": {}
}
}
}
}
},
"second": {
"type": "search",
"status": "success",
"payload": {
"_shards": {
"total": 1,
"failed": 0,
"successful": 1,
"skipped": 0
},
"hits": {
"hits": [
{
"_index": "test123",
"_type": "_doc",
"_source": {
"name": "teju",
"id": 1
},
"_id": "AnFDSW0Bvfhb-n5HmM1w",
"_score": 1
},
{
"_index": "test123",
"_type": "_doc",
"_source": {
"name": "teju",
"id": 1
},
"_id": "k00QSm0Bvfhb-n5H4XUu",
"_score": 1
},
{
"_index": "test123",
"_type": "_doc",
"_source": {
"name": "mast",
"id": 4
},
"_id": "lLtRUm0Bvfhb-n5HEYiF",
"_score": 1
}
],
"total": 3,
"max_score": 1
},
"took": 1,
"timed_out": false
},

"condition": {
  "type": "script",
  "status": "success",
  "met": true
},
"actions": [
  {
    "id": "log",
    "type": "logging",
    "status": "simulated",
    "logging": {
      "logged_text": "{first={_shards={total=1, failed=0, successful=1, skipped=0}, hits={hits=[{_index=test, _type=_doc, _source={name=raju, id=1}, _id=0XA0SW0Bvfhb-n5H1IFL, _score=1.0}, {_index=test, _type=_doc, _source={name=rama, id=2}, _id=0nA1SW0Bvfhb-n5HF5op, _score=1.0}], total=2, max_score=1.0}, took=1, timed_out=false}, second={_shards={total=1, failed=0, successful=1, skipped=0}, hits={hits=[{_index=test123, _type=_doc, _source={name=teju, id=1}, _id=AnFDSW0Bvfhb-n5HmM1w, _score=1.0}, {_index=test123, _type=_doc, _source={name=teju, id=1}, _id=k00QSm0Bvfhb-n5H4XUu, _score=1.0}, {_index=test123, _type=_doc, _source={name=mast, id=4}, _id=lLtRUm0Bvfhb-n5HEYiF, _score=1.0}], total=3, max_score=1.0}, took=1, timed_out=false}}"

},
"messages":

Hey,

please take the time and properly format your message, as this is hard to read. Thanks!

So, the condition only returns true or false, but does not store the result of its calculation somewhere. You can do this either in a transform, or add a field in ctx.payload as part of the condition like ctx.payload.condition_data = [:].

hope this helps!

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.