Script query for child document not working

{
          "script": {
            "script": {
              "source": "doc['tr_billed'].value == doc['tr_bill_discount'].value",
              "lang": "painless"
            },
            "boost": 1
          }
        }

tr_billed and tr_bill_discount are child document fields

this script query inside filter block

Hi @Udayaprakash_S_10d

Provide more data/details to understand your problem.

i have transaction_id child document .i need to fetch  the index if 
tr_billed equal to(==) tr_bill_discount while executing  getting this error

image

{
  "size": 0,
  "query": {
    "bool": {
      "must": [
        {
          "nested": {
            "query": {
              "bool": {
                "filter": [
                  {
                    "range": {
                      "customer_business_relations.customer_on": {
                        "from": "2022-07-27",
                        "to": "2022-07-27",
                        "include_lower": true,
                        "include_upper": true,
                        "boost": 1
                      }
                    }
                  }
                ],
                "adjust_pure_negative": true,
                "boost": 1
              }
            },
            "path": "customer_business_relations",
            "ignore_unmapped": false,
            "score_mode": "none",
            "boost": 1
          }
        },
        {
          "exists": {
            "field": "customer_on",
            "boost": 1
          }
        }
      ],
      "filter": [
        {
          "term": {
            "is_reachable": {
              "value": "YES",
              "boost": 1
            }
          }
        },
        {
          "terms": {
            "account_type": [
              "CUSTOMER"
            ],
            "boost": 1
          }
        },
        {
          "exists": {
            "field": "user_id",
            "boost": 1
          }
        },
        {
          "script": {
            "script": {
              "source": "doc['tr_billed'].value == doc['tr_bill_discount'].value",
              "lang": "painless"
            },
            "boost": 1
          }
        }
      ],
      "adjust_pure_negative": true,
      "boost": 1
    }
  },
  "_source": {
    "includes": [
      "user_id"
    ],
    "excludes": []
  },
  "aggregations": {
    "TRANS_CHILDREN_TYPE": {
      "children": {
        "type": "transaction_id"
      },
      "aggregations": {
        "TRANS_TIME_FILTER_RANGE": {
          "filter": {
            "range": {
              "tr_opened_at": {
                "from": "2022-07-26",
                "to": "2022-07-26",
                "include_lower": true,
                "include_upper": true,
                "boost": 1
              }
            }
          },
          "aggregations": {
            "USERS": {
              "terms": {
                "field": "tr_user_id",
                "size": 25000,
                "min_doc_count": 1,
                "shard_min_doc_count": 0,
                "show_term_doc_count_error": false,
                "order": [
                  {
                    "_count": "desc"
                  },
                  {
                    "_key": "asc"
                  }
                ]
              },
              "aggregations": {
                "TRANSACTIONS": {
                  "value_count": {
                    "field": "transaction_id"
                  }
                },
                "USER_SPEND": {
                  "sum": {
                    "field": "tr_eq_paid"
                  }
                },
                "TOTAL_ITEMS_PURCHASED": {
                  "sum": {
                    "field": "total_tr_items"
                  }
                },
                "USER_TRANS_SELECTOR": {
                  "bucket_selector": {
                    "buckets_path": {
                      "trans_count": "TRANSACTIONS"
                    },
                    "script": {
                      "source": "params.trans_count  >= 1",
                      "lang": "painless"
                    },
                    "gap_policy": "skip"
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

this is my query

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