go-elasticsearch icon indicating copy to clipboard operation
go-elasticsearch copied to clipboard

Feature request: strong type dsl builder

Open ah-its-andy opened this issue 1 year ago • 6 comments

the olivere/elastic supports follow codes: q := elastic.NewBoolQuery() q.Must(elastic.NewTermQuery("id", "1544175232779030532")) It's definitely more readable.

ah-its-andy avatar Aug 25 '22 08:08 ah-its-andy

Thank you for the suggestion!

This is definitely in the long term goals and would qualify as a helper to build specific queries.

It would need to be built by hand upon the generated types to carefully chose what to expose which cannot be done as part of the code generation of the whole typed api.

I'm flagging this issue as an enhancement and will keep it open for future reference!

Anaethelion avatar Aug 25 '22 10:08 Anaethelion

This feature is the biggest gap between olivere and the official lib

JOJO0527 avatar Oct 14 '22 06:10 JOJO0527

I know from previous pull request notes and issue posts as well as the release notes that the typedapi is in alpha. Is there somewhere to subscribe to news on when it will move past the alpha phase? Thanks!

lindsayweil-sl avatar Jan 23 '23 17:01 lindsayweil-sl

Does this include the Filter.query? I rely on this heavily, and am stuck with olivere until I can do this

query := elastic.NewBoolQuery()

if filter.ObserverType != "" { query = FilterQuery(filter.ObserverType, esFieldMapping["observer_type"], query) }

notque avatar Mar 22 '23 05:03 notque

@notque I'm not sure what your FilterQuery method does, however you can already do something like this:

s := &search.Request{Query: types.Query{Bool: types.BoolQuery{
	Filter: []types.Query{
		{
			Term: map[string]types.TermQuery{
				"field": {Value: "value"},
			},
		},
	},
}}}

And run that request through the Search endpoint. If you want to dig further I would advise you to create a specific issue so we can keep this one dedicated to the dsl topic.

Anaethelion avatar Mar 22 '23 16:03 Anaethelion

@Anaethelion understood, I wasn't thinking clearly and didn't show the full piece. I will create a new issue to show. Thanks.

notque avatar Mar 22 '23 16:03 notque