Aggs with painless script on an object containing an array

Hi guys,

I'm using ES 5.0 and how can I represent an object containing an array using painless script, since doc.extra_data.nID_deals.value doesn't seem to do the job?

Take a look:
"inline":"doc.deal_id.value == params.nDealID ? doc.deal_id.value : doc.extra_data.nID_deals.value"

curl -XPOST "http://localhost:9200/tracking-*/_search/?pretty=true&request_cache=true" -d'
{  
  "_source":[  
     "timestamp_ocurred",
     "action",
     "campaign_id",
     "esp_id",
     "user_id",
     "geo",
     "extra_data.nID_deals",
     "deal_id"
  ],
  "query":{  
     "multi_match":{  
        "query":465,
        "fields":[  
           "deal_id",
           "extra_data.nID_deals"
        ]
     }
  },
  "size":0,
  "aggs":{  
     "DEAL":{  
        "terms":{  
           "script":{  
              "lang":"painless",
              "inline":"doc.deal_id.value == params.nDealID ? doc.deal_id.value : doc.extra_data.nID_deals.value",
              "params":{
                "nDealID":465
              }
           }
        }
...

TIA

That should work, unless one of the intermediate objects is mapped as nested. Is it the case?

It should @jpountz

Here's the return:

{
  "took" : 11995,
  "timed_out" : false,
  "_shards" : {
    "total" : 453,
    "successful" : 98,
    "failed" : 355,
    "failures" : [
      {
        "shard" : 0,
        "index" : "tracking-2016.08.10",
        "node" : "tiMdzgSARAu-2ue5LmbLcg",
        "reason" : {
          "type" : "script_exception",
          "reason" : "runtime error",
          "caused_by" : {
            "type" : "illegal_argument_exception",
            "reason" : "No field found for [deal_id] in mapping with types []"
          },
          "script_stack" : [
            "org.elasticsearch.search.lookup.LeafDocLookup.get(LeafDocLookup.java:80)",
            "doc.deal_id.value == params.nDealID ? doc.deal_id.value : doc.extra_data.nID_deals.value",
            "   ^---- HERE"
          ],
          "script" : "doc.deal_id.value == params.nDealID ? doc.deal_id.value : doc.extra_data.nID_deals.value",
          "lang" : "painless"
        }
      },
      {
        "shard" : 0,
        "index" : "tracking-2016.11.22",
        "node" : "tiMdzgSARAu-2ue5LmbLcg",
        "reason" : {
          "type" : "illegal_argument_exception",
          "reason" : "Fielddata is disabled on text fields by default. Set fielddata=true on [action] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory."
        }
      }
    ]
  },
  "hits" : {
    "total" : 0,
    "max_score" : 0.0,
    "hits" : [ ]
  },
  "aggregations" : {
    "DEAL" : {
      "doc_count_error_upper_bound" : 0,
      "sum_other_doc_count" : 0,
      "buckets" : [ ]
    }
  }
}

It looks like at least one of the queried indices does not have a mapping for the deal_id field.

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