Skip to content

types.MultiTerms needs to support Script #1022

@stivens13

Description

@stivens13

Hi all!

Thank you for your work. I've started using elasticsearch typed queries to convert existing metrics codebase and produce new queries as well and am thrilled about how much safer and easier it is. However, the issue below is something that prevents a release of a new substantial change I'm working on.

Go version: 1.24.4
elasticsearch-go: 9.0.0 (latest)

The following is a part of a valid ES query

"multi_terms": map[string]interface{}{
	"terms": []map[string]interface{}{
		{"field": "request.headers.Host.raw"},
		{"script": "doc['request.route.raw'].value.replace('//', '/')"},
		{"field": "request.verb"},
	},
	"size": 999,
},

However, the ES Type MultiTermLookup does not support Script as a field, only Field itself is supported. This results in the impossibility of the proper conversion of the former raw query to es dsl

MultiTerms: &types.MultiTermsAggregation{
	Terms: []types.MultiTermLookup{
		{
			Field: "request.headers.Host.raw",
		},
		{
			Script: "doc['request.route.raw'].value.replace('//', '/')",     ------->  Unsuported
		},
		{
			Field: "request.verb",
		},
	},
},

The only available alternative is to replace the script with value itself, however, it produces incorrect results because request.route.raw is not normalized (Moesif)

MultiTerms: &types.MultiTermsAggregation{
	Terms: []types.MultiTermLookup{
		{
			Field: "request.headers.Host.raw",
		},
		{
			Field: "request.route.raw",     ------->  Supported, but some entries are silently dropped
		},
		{
			Field: "request.verb",
		},
	},
},

Unfortunately, in addition to MultiTermLookup's Script field missing, there's also no dedicated way to manually override / enrich the entry (e.g. assign map[string]string to a meta field of MultTermLookup or something like that). Basically, this leads to a situation where one small feature is unsupported and it invalidates the usage of elasticsearch-go completely for this specific use case

In case I'm missing something, let me know and I'll take advice if there is any. Feel free to request any additional info about the problem

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions