elastic / go-elasticsearch

The official Go client for Elasticsearch
https://github.com/elastic/go-elasticsearch#go-elasticsearch
Apache License 2.0
38 stars 617 forks source link

Feature request: strong type dsl builder #526

Open ah-its-andy opened 2 years ago

ah-its-andy commented 2 years ago

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

Anaethelion commented 2 years ago

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!

JOJO0527 commented 2 years ago

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

lindsayweil-sl commented 1 year ago

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!

notque commented 1 year ago

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) }

Anaethelion commented 1 year ago

@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.

notque commented 1 year ago

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