Description
Is your feature request related to a problem? Please describe
In #6507, we add the flat object type. In current implementation, we use two stages to process the flat_object field in the document. First we use the JsonToStringXContentParser
to collect all the keys and values (keyList
, valueList
and valueAndPathList
) in the field and convert to XContentParser
for return. The Lucene fields are then constructed by parsing the fields in the XContentParser
.
For a field of flat_object type in a document, the following internal fields will be created by default:
- root StringField and SortedSetDocValuesField for each subfield key(prefiexed by root field name);
value
StringField and SortedSetDocValuesField for each subfield value;valueAndPath
StringField and SortedSetDocValuesField for each subfield;_field_name
StringField for eachvalue
andvalueAndPath
.
PUT test
{
"mappings": {
"properties": {
"field1": {
"properties": {
"field2": {
"type": "flat_object"
}
}
}
}
}
}
PUT test/_bulk
{"index": {}}
{"field1": {"field2": {"a": "1", "b": "2"}}}
For example, the request above generates the fields listed below.
There are several issues around the flat object field.
- If a subfield in the flat_object field suffixed by
VALUE_SUFFIX
(._value
) orVALUE_AND_PATH_SUFFIX
(._valueAndPath
), some extra unexpected field may be created.
-
We use '=' to concat subfield key and value, if a subfield key contains '=', the prefix query may return wrong results.
-
The root fields is confusing and unnecessary. AFAIK, the root field is use to execute exist query and build fielddata, but it doesn't be generated correctly. For example, if we have document
{"field1": {"field2": {"field3": {"a": "1", "b": "2"}}}}
, andfield2
is flat_object field. After processed, the root fields contains valuesfield1.field2.a
,field1.field2.b
andfield1.field2.field3
. The exist query offield1.field2.field3.a
doesn't return correct result. On the other hand, I don't know is there any meaning to aggregate or sort on the subfield keys. In fact, I don't think that we need to support aggs on flat_object field, it's a object, not a scalar value. If we do need, then we should aggregate on the subfield values, not the subfield keys. Of course, it still makes sense to aggregate subfields, we can utilize the valueAndPath field to support this. -
Creating
_field_name
field forvalue
andvalueAndPath
is meaningless. The_field_name
field is used by exist query, we just need to create it for each full leaf path of subfield. -
The value of SortedSetDocValuesField of
value
andvalueAndPath
has unnecessary prefix. When create SortedSetDocValuesField, we use root field name as the prefix of value. -
Two-stage processing is unnecessary. In the process of converting to JSON strings, we use a lot of additional resources, this is really unnecessary, we can add the corresponding field to parse context during the process.
Describe the solution you'd like
- Use one-stage processing;
- Remove the FlatObjecField;
- Support the aggs on the subfield, but not the root field, which means the fielddata is not supported on the root field but the subfield;
- For the indices created after 2.18.0, remove the prefix of the value of SortedSetDocValuesField.
In addition, I have no good idea to fix the issue 2, any suggestions about this or the overall issue are welcome.
Related component
Search
Describe alternatives you've considered
No response
Additional context
No response
Metadata
Metadata
Assignees
Type
Projects
Status