4

I am using Elasticsearch 6.2 which uses painless for the inline scripting. One of the fields in my doc has mapping:

"gap_days": {"type": "integer"}

And I have a painless script for search and the few lines are:

int gap = 10; //initialize to a default value
if (doc.containsKey('gap_days')) {
  if (doc['gap_days'].value != null) {
    gap = doc['gap_days'].value;
  }
}

But this keeps throwing an error:

script_stack: [
  "gap = doc['gap_days'].value; } } ",
  " ^---- HERE"
],
caused_by: {
  reason: "cannot convert MethodHandle(Longs)long to (Object)int",
  type: "wrong_method_type_exception"
},
reason: "runtime error"

I tried to look into all unique doc['gap_days'] values in the index, and you can see all of them are integer in all documents

"aggregations": {
  "uniq_gaps": {
    "doc_count_error_upper_bound": 0,
    "sum_other_doc_count": 342,
    "buckets": [
      {
        "key": 0,
        "doc_count": 31607
      },
      {
        "key": 365,
        "doc_count": 15119
      },
      {
        "key": 5,
        "doc_count": 2639
      },
      {
        "key": 21,
        "doc_count": 1784
      },
      {
        "key": 14,
        "doc_count": 1229
      },
      {
        "key": 3,
        "doc_count": 1073
      },
      {
        "key": 7,
        "doc_count": 979
      },
      {
        "key": 2,
        "doc_count": 728
      },
      {
        "key": 4,
        "doc_count": 291
      },
      {
        "key": 10,
        "doc_count": 170
      }
    ]
  }
}

Then why does it throw an exception saying cannot convert MethodHandle(Longs)long to (Object)int and my script stops working. Any idea how to fix this problem?

JVK
  • 3,782
  • 8
  • 43
  • 67
  • I'm interested to see your real mapping, i.e. the one you get when running `curl -XGET localhost:9200/your_index`. Please share – Val Jun 13 '18 at 03:14
  • @Val It is an integer, trust me =) even in the mapping that comes back from `curl -XGET localhost:9200/your_index` I found something strange about my case, please see here https://discuss.elastic.co/t/elasticsearch-6-painless-query-exception/135588/6 – JVK Jun 13 '18 at 23:17
  • Apparently, you got it solved, glad you figured out. – Val Jun 14 '18 at 03:13
  • @Val yeah I got it solved, but it is weird that data type integer needs to accessed as long in the script :| – JVK Jun 14 '18 at 04:49
  • Well Igor's answer is pretty clear "for simplicity sake all integral data types are represented as longs and all real data types are represented as doubles." ;-) – Val Jun 14 '18 at 05:10

0 Answers0