Skip to content

Synthetic _source can't be retrieved with overlapping keys in flattened field #122936

Open
@flash1293

Description

@flash1293

Elasticsearch Version

main

Installed Plugins

No response

Java Version

bundled

OS Version

macOS 15.3

Problem Description

When using flattened fields in a logsdb index, synthetic source is used to reconstruct the value of the flattened field. In case the key/value pairs in the flattened field have an object/scalar mismatch, the search request fails because the _source can't be constructed.

Steps to Reproduce

PUT my-index
{
  "settings": {
    "mode": "logsdb"
  },
  "mappings": {
    "properties": {
        "test": {
            "type": "flattened"
        }
    }
  }
}

POST my-index/_doc
{
  "@timestamp": "2025",
  "test": {
      "nested.doublynested": 123,
      "nested": {
        "doublynested": {
          "gotcha": true
        }
      }
    }
}

GET my-index/_search // returns 500

Logs (if relevant)

failure encoding chunk com.fasterxml.jackson.core.JsonParseException: Duplicate field 'doublynested'
   │       at [Source: (org.elasticsearch.common.io.stream.ByteBufferStreamInput); line: 1, column: 112]
   │      	at [email protected]/com.fasterxml.jackson.core.json.JsonReadContext._checkDup(JsonReadContext.java:250)
   │      	at [email protected]/com.fasterxml.jackson.core.json.JsonReadContext.setCurrentName(JsonReadContext.java:244)
   │      	at [email protected]/com.fasterxml.jackson.core.json.UTF8StreamJsonParser.nextToken(UTF8StreamJsonParser.java:758)
   │      	at [email protected]/com.fasterxml.jackson.core.JsonGenerator._copyCurrentContents(JsonGenerator.java:2657)
   │      	at [email protected]/com.fasterxml.jackson.core.JsonGenerator.copyCurrentStructure(JsonGenerator.java:2638)
   │      	at [email protected]/org.elasticsearch.xcontent.provider.json.JsonXContentGenerator.copyCurrentStructure(JsonXContentGenerator.java:540)
   │      	at [email protected]/org.elasticsearch.xcontent.provider.json.JsonXContentGenerator.writeRawField(JsonXContentGenerator.java:475)
   │      	at [email protected]/org.elasticsearch.xcontent.provider.json.JsonXContentGenerator.writeRawField(JsonXContentGenerator.java:466)
   │      	at [email protected]/org.elasticsearch.xcontent.XContentBuilder.rawField(XContentBuilder.java:1205)
   │      	at [email protected]/org.elasticsearch.common.xcontent.XContentHelper.writeRawField(XContentHelper.java:578)
   │      	at [email protected]/org.elasticsearch.search.SearchHit.toInnerXContent(SearchHit.java:856)
   │      	at [email protected]/org.elasticsearch.search.SearchHit.toXContent(SearchHit.java:801)
   │      	at [email protected]/org.elasticsearch.rest.ChunkedRestResponseBodyPart$1.encodeChunk(ChunkedRestResponseBodyPart.java:161)
   │      	at [email protected]/org.elasticsearch.rest.RestController$EncodedLengthTrackingChunkedRestResponseBodyPart.encodeChunk(RestController.java:1002)
   │      	at [email protected]/org.elasticsearch.http.netty4.Netty4HttpPipeliningHandler.writeChunk(Netty4HttpPipeliningHandler.java:440)
   │      	at [email protected]/org.elasticsearch.http.netty4.Netty4HttpPipeliningHandler.doWriteChunkedResponse(Netty4HttpPipeliningHandler.java:267)
   │      	at [email protected]/org.elasticsearch.http.netty4.Netty4HttpPipeliningHandler.doWrite(Netty4HttpPipeliningHandler.java:235)
   │      	at [email protected]/org.elasticsearch.http.netty4.Netty4HttpPipeliningHandler.write(Netty4HttpPipeliningHandler.java:188)
   │      	at [email protected]/io.netty.channel.AbstractChannelHandlerContext.invokeWrite0(AbstractChannelHandlerContext.java:891)
   │      	at [email protected]/io.netty.channel.AbstractChannelHandlerContext.invokeWriteAndFlush(AbstractChannelHandlerContext.java:956)
   │      	at [email protected]/io.netty.channel.AbstractChannelHandlerContext$WriteTask.run(AbstractChannelHandlerContext.java:1263)
   │      	at [email protected]/io.netty.util.concurrent.AbstractEventExecutor.runTask(AbstractEventExecutor.java:173)
   │      	at [email protected]/io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:166)
   │      	at [email protected]/io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:472)
   │      	at [email protected]/io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:569)
   │      	at [email protected]/io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997)
   │      	at [email protected]/io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
   │      	at java.base/java.lang.Thread.run(Thread.java:1575)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions