Haoyuan Ge
Haoyuan Ge

Reputation: 3689

Any way(plugin) to parse kibana query syntax to elasticsearch api body?

I have a search engine app which does not use kibana. I want to translate query like (mysql.method: INSERT OR mysql.method: UPDATE) AND responsetime: [30 TO 50) into rest api body:

{
    "filtered" : {
      "filter" : {
        "and":[
          "or": [
            { "mysql.method" : "INSERT" },
            { "mysql.method" : "UPDATE" }
          ],
          "range": {
            "responsetime": {
              "gte":30,
              "lt":50
            }
          }
        ]
      }
    }
  }

Is there any plugin to achieve this? Hopefully in js.

Upvotes: 0

Views: 627

Answers (1)

Hugodby
Hugodby

Reputation: 1183

No need to use any plugin. You can use directly the query string query. It work with the same syntax as Kibana "search bar".

{
    "query_string" : {
        "query" : "(mysql.method:INSERT OR mysql.method:UPDATE) AND responsetime:[30 TO 50]"
    }
}

https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html

Upvotes: 2

Related Questions