OpenSearch QueryBuilder in Golang

Hello,
I am using a golang client to talk to Opensearch version 1.2.4 .

I have been looking for a while to find out elastic search equivalent of "gopkg.in/olivere/elastic.v6" in opensearch to build queries. At the moment I am using the following library "github.com/opensearch-project/opensearch-go".

I am looking for built in APIs like NewTermQuery(), NewBoolQuery(), ShouldQuery() etc in opensearch library.

Are these APIs available in opensearch golang libraries?

Hi @sresd - I don’t know off the top of my head - I’m definitely not an expert at go. I did a quick look through the source code of the go libraries. It looks like there’s a short little piece of go for each of the methods that can be called. Have a peek at this:

https://github.com/opensearch-project/opensearch-go/tree/main/opensearchapi

You might be able to find your answer there with a bit of reading. Let me know if you need further help. I’ll be happy to see if I can draw in another expert. :slight_smile:

Nate

Hello @nateynate ,

Thanks for looking into this. As a matter of fact I went through these files before reaching out here.
if my understanding is right, these APIs do not talk about query building as such but they are mostly about talking to opensearch if you have the query in hand.

Also Query is defined as a string in these files which makes me wonder even more if APIs are builtin to construct it.

query builder for opensearch GitHub - defensestation/osquery: An idiomatic Go query builder for OpenSearch

How to build queries safely in golang : OpenSearch Query Builder in Golang | by Confused Cyber Warrior | Aug, 2024 | Medium