opensearch-project / OpenSearch

🔎 Open source distributed and RESTful search engine.
https://opensearch.org/docs/latest/opensearch/index/
Apache License 2.0
9.12k stars 1.69k forks source link

[BUG] ScriptProcessor fails with char data type #14382

Open andrross opened 1 month ago

andrross commented 1 month ago

Describe the bug

The following ingest pipeline will fail when indexing a document:

{
  "description": "_description",
  "processors": [
    {
      "script" : {
        "source" : "ctx.char = (char)'a'"
      }
    },
    {
      "script" : {
        "source" : "ctx.other_field = 'other_field'"
      }
    }
  ]
}

Issue #14379 is a very similar symptom for other data types, but the cause appears to be different. I have a fix ready to go for #14379 but this issue appears to be related to XContent serialization and it wasn't immediately obvious to me how to fix it, so I've created a separate issue. Also the other issue was a regression introduced in OpenSearch 2.8, whereas this issue appears to have existed prior to OpenSearch 2.8.

Related component

Indexing

To Reproduce

Index a document with the pipeline defined above.

Expected behavior

Success

Additional Details

  1> Caused by: java.lang.IllegalArgumentException: cannot write xcontent for unknown value of type class java.lang.Character
  1>    at org.opensearch.core.xcontent.XContentBuilder.unknownValue(XContentBuilder.java:866)
  1>    at org.opensearch.core.xcontent.XContentBuilder.map(XContentBuilder.java:928)
  1>    at org.opensearch.core.xcontent.XContentBuilder.map(XContentBuilder.java:903)
  1>    at org.opensearch.action.index.IndexRequest.source(IndexRequest.java:384)
  1>    at org.opensearch.ingest.IngestService.updateIndexRequestWithIngestDocument(IngestService.java:1314)
  1>    at org.opensearch.ingest.IngestService.lambda$innerExecute$11(IngestService.java:1044)
  1>    at org.opensearch.ingest.IngestDocument.lambda$executePipeline$0(IngestDocument.java:814)
  1>    at org.opensearch.ingest.Pipeline.lambda$execute$0(Pipeline.java:140)
  1>    at org.opensearch.ingest.CompoundProcessor.innerExecute(CompoundProcessor.java:260)
  1>    at org.opensearch.ingest.CompoundProcessor.lambda$innerExecute$4(CompoundProcessor.java:287)
  1>    at org.opensearch.ingest.Processor.execute(Processor.java:77)
  1>    at org.opensearch.ingest.CompoundProcessor.innerExecute(CompoundProcessor.java:269)
  1>    at org.opensearch.ingest.CompoundProcessor.lambda$innerExecute$4(CompoundProcessor.java:287)
  1>    at org.opensearch.ingest.Processor.execute(Processor.java:77)
  1>    at org.opensearch.ingest.CompoundProcessor.innerExecute(CompoundProcessor.java:269)
  1>    at org.opensearch.ingest.CompoundProcessor.execute(CompoundProcessor.java:153)
  1>    at org.opensearch.ingest.Pipeline.execute(Pipeline.java:134)
  1>    at org.opensearch.ingest.IngestDocument.executePipeline(IngestDocument.java:807)
  1>    at org.opensearch.ingest.IngestService.innerExecute(IngestService.java:1034)
  1>    at org.opensearch.ingest.IngestService.executePipelines(IngestService.java:881)
  1>    ... 6 more
peternied commented 1 month ago

[Triage - attendees 1 2 3 4 5] @andrross Thanks for creating this issue

vikasvb90 commented 2 weeks ago

@andrross Can we close this now as PR for the fix has been merged?

andrross commented 2 weeks ago

@vikasvb90 #14379 has been fixed, but has this one been fixed yet?

vikasvb90 commented 1 week ago

Ah ok! No, char issue is still pending. Please keep it open