Skip to content

[Enhancement] Enable Partial Flat_object Field Type #7136

@mingshl

Description

@mingshl

Is your feature request related to a problem? Please describe.
Currently, Only root fields of a json object can be defined as a flat object. You cannot define an object that is part of another JSON object as a flat object because when a flat object it is parses to a string, the nested architecture of the leaves is lost.

Describe the solution you'd like
in flat_object, there are no subfields in mapping, but when querying, flat_object field mapper dynamically create a new flat_object field type for the subfields, if they are not existed in then mappings, then when the query finished, the flat_object field type will be pop out of stack. It does not add to mappings.

The idea solution is to make the dynamically flat_object type to remember the path before it gets partially flatten.

For example, for a sample issue document:

 {
  "issue": {
    "number": "123456",
    "labels": {
      "version": "2.1",
      "backport": [
        "2.0",
        "1.3"
      ],
      "category": {
        "type": "API",
        "level": "enhancement"
      }
    }
  }
}

Currently, we need to define the mapping from the root of JSON,

 PUT /test-index/
{
  "mappings": {
    "properties": {
      "issue": {
            "type": "flat_object"
          }
        }
    }
  }

In the enhancement, we can define part of the JSON to be other field type, such as double and keyword

ideal use case 1: issue.number to be keyword type, while issue.labels is a flat_object type.

 PUT /test-index/
{
  "mappings": {
    "properties": {
      "issue": {
        "properties": {
          "number": {
            "type": "keyword"
          },
          "labels": {
            "type": "flat_object"
          }
        }
      }
    }
  }
}

ideal use case 2: issue.number to be double type, while issue.labels is a flat_object type. Users can do aggregation the documents on issue.number. This can resolve the concerns that flat_object can not support numerical parsing operations, then the users can define part of the json to be type specific field type when aggregation, sorting are needed.

 PUT /test-index/
{
  "mappings": {
    "properties": {
      "issue": {
        "properties": {
          "number": {
            "type": "double"
          },
          "labels": {
            "type": "flat_object"
          }
        }
      }
    }
  }
}

Metadata

Metadata

Assignees

Labels

SearchSearch query, autocomplete ...etcenhancementEnhancement or improvement to existing feature or requestv2.9.0'Issues and PRs related to version v2.9.0'

Type

No type

Projects

Status

✅ Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions