Skip to content

"composite runtime fields" are not supported by the language client which is not compliant with the spec. #551

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
MichaelOpitz2 opened this issue Apr 6, 2023 · 0 comments · Fixed by #776

Comments

@MichaelOpitz2
Copy link

MichaelOpitz2 commented Apr 6, 2023

Java API client version

8.5.2

Java version

11

Elasticsearch Version

8.5.2

Problem description

The language-client does not support composite runtime fields. The spec states for the Search API, that runtime_mappings should support "composite" fields. This is not the case with the language-client:
`runtime_mappings

(Optional, object of objects) Defines one or more [runtime fields](https://www.elastic.co/guide/en/elasticsearch/reference/current/runtime-search-request.html) in the search request. These fields take precedence over mapped fields with the same name.
Properties of runtime_mappings objects

<field-name>

    (Required, object) Configuration for the runtime field. The key is the field name.
    Properties of <field-name>

    type

        (Required, string) [Field type](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-types.html), which can be any of the following:

            boolean
            composite
            date
            double
            geo_point
            ip
            keyword
            long
            [lookup](https://www.elastic.co/guide/en/elasticsearch/reference/current/runtime-retrieving-fields.html#lookup-runtime-fields)

    script

        (Optional, string) [Painless script](https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting-using.html) executed at query time. The script has access to the entire context of a document, including the original _source and any mapped fields plus their values.`

Imho, the change to the spec would be easy:

_types/mapping/RuntimeFields.ts:

import { Dictionary } from '@spec_utils/Dictionary'
import { Field } from '@_types/common'
import { Script } from '@_types/Scripting'

export type RuntimeFields = Dictionary<Field, RuntimeField>

export class RuntimeField {
  fields?: Dictionary<string, Dictionary<string, RuntimeFieldType>>;
  format?: string
  script?: Script
  type: RuntimeFieldType
}

export enum RuntimeFieldType {
  boolean = 0,
  composite = 1
  date = 2,
  double = 3,
  geo_point = 4,
  ip = 5,
  keyword = 6,
  long = 7,
  lookup
}

The JSON-Output would be:

   {
      "kind": "interface",
      "name": {
        "name": "RuntimeField",
        "namespace": "_types.mapping"
      },
      "properties": [
        {
          "name": "fields",
          "required": false,
          "type": {
            "key": {
              "kind": "instance_of",
              "type": {
                "name": "string",
                "namespace": "_builtins"
              }
            },
            "kind": "dictionary_of",
            "singleKey": false,
            "value": {
              "key": {
                "kind": "instance_of",
                "type": {
                  "name": "string",
                  "namespace": "_builtins"
                }
              },
              "kind": "dictionary_of",
              "singleKey": false,
              "value": {
                "kind": "instance_of",
                "type": {
                  "name": "RuntimeFieldType",
                  "namespace": "_types.mapping"
                }
              }
            }
          }
        },
        {
          "name": "format",
          "required": false,
          "type": {
            "kind": "instance_of",
            "type": {
              "name": "string",
              "namespace": "_builtins"
            }
          }
        },
        {
          "name": "script",
          "required": false,
          "type": {
            "kind": "instance_of",
            "type": {
              "name": "Script",
              "namespace": "_types"
            }
          }
        },
        {
          "name": "type",
          "required": true,
          "type": {
            "kind": "instance_of",
            "type": {
              "name": "RuntimeFieldType",
              "namespace": "_types.mapping"
            }
          }
        }
      ],
      "specLocation": "C:/dev/elasticsearch-specification/specification/_types/mapping/RuntimeFields.ts#L26-L31"
    },
    {
      "kind": "enum",
      "members": [
        {
          "name": "boolean"
        },
        {
          "name": "composite"
        },
        {
          "name": "date"
        },
        {
          "name": "double"
        },
        {
          "name": "geo_point"
        },
        {
          "name": "ip"
        },
        {
          "name": "keyword"
        },
        {
          "name": "long"
        },
        {
          "name": "lookup"
        }
		
      ],
      "name": {
        "name": "RuntimeFieldType",
        "namespace": "_types.mapping"
      },
      "specLocation": "C:/dev/elasticsearch-specification/specification/_types/mapping/RuntimeFields.ts#L33-L42"
    },

Maybe, the "Dictionary" would have to be replaced with "SingleKeyDictionary".

The class "RuntimeField.java" would need to serialize the "field" field with:

	protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {

		if (ApiTypeHelper.isDefined(this.fields)) {
			generator.writeKey("fields");
			generator.writeStartObject();
			for (Map.Entry<String, Map<String,RuntimeFieldType>> cf : this.fields.entrySet()) {
				generator.writeKey(cf.getKey());
				generator.writeStartObject();
				for(Map.Entry<String,RuntimeFieldType> spec : cf.getValue().entrySet()) {
					generator.writeKey(spec.getKey());
					generator.write(spec.getValue().jsonValue());
				}
				generator.writeEnd();
			}
			generator.writeEnd();
		}

		if (this.format != null) {
			generator.writeKey("format");
			generator.write(this.format);

		}
		if (this.script != null) {
			generator.writeKey("script");
			this.script.serialize(generator, mapper);

		}
		generator.writeKey("type");
		this.type.serialize(generator, mapper);

	}

...

	protected static void setupRuntimeFieldDeserializer(ObjectDeserializer<RuntimeField.Builder> op) {

		op.add(Builder::fields,
				JsonpDeserializer.stringMapDeserializer(
					JsonpDeserializer.stringMapDeserializer(RuntimeFieldType._DESERIALIZER)),
				"fields");
		op.add(Builder::format, JsonpDeserializer.stringDeserializer(), "format");
		op.add(Builder::script, Script._DESERIALIZER, "script");
		op.add(Builder::type, RuntimeFieldType._DESERIALIZER, "type");

	}

What is the reason, that composite runtime fields are not supported?

Unfortunately, I was not able to check the Java result, because I could not find the code-generator project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant