Skip to content

Scripts can't handle IP fields #20067

@Bargs

Description

@Bargs

Elasticsearch version: master

Plugins installed: none

JVM version: 1.8.0_60

OS version: OSX El Capitan

Description of the problem including expected versus actual behavior:

I tried to create a script_field using Painless that accesses an IP type field. I expected to get the long representation of the IP but instead ES threw an error. I tried both implicit and explicit typing, but both threw an error. Realized IP fields aren't stored as longs in 5.0, but I'm still wondering how one might access IP values in painless

Steps to reproduce:

  1. Create an index with an IP field (makelogs works well)
  2. Issue a query with the following script_field in the request body:
"script": {
  "inline": "return doc['ip'].value;",
  "lang": "painless"
}

ES Response:

{
  "error": {
    "root_cause": [
      {
        "type": "script_exception",
        "reason": "runtime error",
        "script_stack": [
          "org.apache.lucene.util.UnicodeUtil.UTF8toUTF16(UnicodeUtil.java:596)",
          "org.apache.lucene.util.BytesRef.utf8ToString(BytesRef.java:152)",
          "org.elasticsearch.index.fielddata.ScriptDocValues$Strings.getValue(ScriptDocValues.java:83)",
          "return doc['ip'].value;",
          "                ^---- HERE"
        ],
        "script": "return doc['ip'].value;",
        "lang": "painless"
      }
    ],
    "type": "search_phase_execution_exception",
    "reason": "all shards failed",
    "phase": "query_fetch",
    "grouped": true,
    "failed_shards": [
      {
        "shard": 0,
        "index": "logstash-0",
        "node": "00s71MPnSRenvz6mflLQeQ",
        "reason": {
          "type": "script_exception",
          "reason": "runtime error",
          "caused_by": {
            "type": "array_index_out_of_bounds_exception",
            "reason": "16"
          },
          "script_stack": [
            "org.apache.lucene.util.UnicodeUtil.UTF8toUTF16(UnicodeUtil.java:596)",
            "org.apache.lucene.util.BytesRef.utf8ToString(BytesRef.java:152)",
            "org.elasticsearch.index.fielddata.ScriptDocValues$Strings.getValue(ScriptDocValues.java:83)",
            "return doc['ip'].value;",
            "                ^---- HERE"
          ],
          "script": "return doc['ip'].value;",
          "lang": "painless"
        }
      }
    ],
    "caused_by": {
      "type": "script_exception",
      "reason": "runtime error",
      "caused_by": {
        "type": "array_index_out_of_bounds_exception",
        "reason": "16"
      },
      "script_stack": [
        "org.apache.lucene.util.UnicodeUtil.UTF8toUTF16(UnicodeUtil.java:596)",
        "org.apache.lucene.util.BytesRef.utf8ToString(BytesRef.java:152)",
        "org.elasticsearch.index.fielddata.ScriptDocValues$Strings.getValue(ScriptDocValues.java:83)",
        "return doc['ip'].value;",
        "                ^---- HERE"
      ],
      "script": "return doc['ip'].value;",
      "lang": "painless"
    }
  },
  "status": 500
}

Provide logs (if relevant):

INFO - ? - ? - [2016-08-18 18:10:08,747][WARN ][rest.suppressed          ] path: /logstash-*/_search, params: {index=logstash-*}
INFO - ? - ? - Failed to execute phase [query_fetch], all shards failed; shardFailures {[00s71MPnSRenvz6mflLQeQ][logstash-0][0]: RemoteTransportException[[00s71MP][127.0.0.1:9300][indices:data/read/search[phase/query+fetch]]]; nested: ScriptException[runtime error]; nested: ArrayIndexOutOfBoundsException[16]; }
INFO - ? - ? - at org.elasticsearch.action.search.AbstractSearchAsyncAction.onFirstPhaseResult(AbstractSearchAsyncAction.java:225)
INFO - ? - ? - at org.elasticsearch.action.search.AbstractSearchAsyncAction$1.onFailure(AbstractSearchAsyncAction.java:171)
INFO - ? - ? - at org.elasticsearch.action.ActionListenerResponseHandler.handleException(ActionListenerResponseHandler.java:51)
INFO - ? - ? - at org.elasticsearch.transport.TransportService$ContextRestoreResponseHandler.handleException(TransportService.java:934)
INFO - ? - ? - at org.elasticsearch.transport.TransportService$DirectResponseChannel.processException(TransportService.java:1035)
INFO - ? - ? - at org.elasticsearch.transport.TransportService$DirectResponseChannel.sendResponse(TransportService.java:1013)
INFO - ? - ? - at org.elasticsearch.transport.TransportService$5.onFailure(TransportService.java:528)
INFO - ? - ? - at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.onFailure(ThreadContext.java:496)
INFO - ? - ? - at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:39)
INFO - ? - ? - at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
INFO - ? - ? - at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
INFO - ? - ? - at java.lang.Thread.run(Thread.java:745)
INFO - ? - ? - Caused by: RemoteTransportException[[00s71MP][127.0.0.1:9300][indices:data/read/search[phase/query+fetch]]]; nested: ScriptException[runtime error]; nested: ArrayIndexOutOfBoundsException[16];
INFO - ? - ? - Caused by: ScriptException[runtime error]; nested: ArrayIndexOutOfBoundsException[16];
INFO - ? - ? - at org.elasticsearch.painless.ScriptImpl.convertToScriptException(ScriptImpl.java:176)
INFO - ? - ? - at org.elasticsearch.painless.ScriptImpl.run(ScriptImpl.java:123)
INFO - ? - ? - at org.elasticsearch.search.fetch.script.ScriptFieldsFetchSubPhase.hitExecute(ScriptFieldsFetchSubPhase.java:52)
INFO - ? - ? - at org.elasticsearch.search.fetch.FetchPhase.execute(FetchPhase.java:163)
INFO - ? - ? - at org.elasticsearch.search.SearchService.executeFetchPhase(SearchService.java:369)
INFO - ? - ? - at org.elasticsearch.search.action.SearchTransportService$SearchQueryFetchTransportHandler.messageReceived(SearchTransportService.java:339)
INFO - ? - ? - at org.elasticsearch.search.action.SearchTransportService$SearchQueryFetchTransportHandler.messageReceived(SearchTransportService.java:336)
INFO - ? - ? - at org.elasticsearch.transport.TransportRequestHandler.messageReceived(TransportRequestHandler.java:33)
INFO - ? - ? - at org.elasticsearch.transport.RequestHandlerRegistry.processMessageReceived(RequestHandlerRegistry.java:69)
INFO - ? - ? - at org.elasticsearch.transport.TransportService$5.doRun(TransportService.java:517)
INFO - ? - ? - at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:510)
INFO - ? - ? - at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37)
INFO - ? - ? - at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
INFO - ? - ? - at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
INFO - ? - ? - at java.lang.Thread.run(Thread.java:745)
INFO - ? - ? - Caused by: java.lang.ArrayIndexOutOfBoundsException: 16
INFO - ? - ? - at org.apache.lucene.util.UnicodeUtil.UTF8toUTF16(UnicodeUtil.java:596)
INFO - ? - ? - at org.apache.lucene.util.BytesRef.utf8ToString(BytesRef.java:152)
INFO - ? - ? - at org.elasticsearch.index.fielddata.ScriptDocValues$Strings.getValue(ScriptDocValues.java:83)
INFO - ? - ? - at org.elasticsearch.painless.Executable$Script.execute(return doc['ip'].value; @ <inline script>:17)
INFO - ? - ? - at org.elasticsearch.painless.ScriptImpl.run(ScriptImpl.java:121)
INFO - ? - ? - ... 13 more

Metadata

Metadata

Assignees

Labels

:Core/Infra/ScriptingScripting abstractions, Painless, and Mustache

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions