Querying ElasticSearch from Go

149 views
Skip to first unread message

David Sofo

unread,
Sep 3, 2016, 6:21:18 PM9/3/16
to golang-nuts
Hi,

I have a set of ElasticSearch queries in string format already. I don't have to rewrite the queries. How to query ElasticSearch using these strings.
A string query can have this form:

query := `{
        "query":{
            "bool": {
                "should": [
                {"match": {"name": "Rodri"}},
                {"match": {"name": "Massadra"}}
                ]
            }
        }
        }`

I try to use this client https://github.com/olivere/elastic  but I didn't find a way to do it.

Thank you any suggestion is welcome
David


Matt Harden

unread,
Sep 3, 2016, 7:23:04 PM9/3/16
to David Sofo, golang-nuts
Maybe you want a QueryStringQuery?

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Matt Harden

unread,
Sep 3, 2016, 7:43:08 PM9/3/16
to David Sofo, golang-nuts
OK so that was wrong. Here's what I found:

First, it looks like you can simply send a "GET _search" to the elasticsearch server with the JSON request as the body. See https://www.elastic.co/guide/en/elasticsearch/reference/current/query-filter-context.html. So maybe drop the client and just use http.Get().

Second, If you want to use that client, it looks like you can use RawStringQuery. See the example in that doc.

David Sofo

unread,
Sep 4, 2016, 9:04:27 AM9/4/16
to golang-nuts
Thank you for your replies. 
David
Reply all
Reply to author
Forward
0 new messages