Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Query to see if a field contains a string using Query DSL

I am trying to filter Kibana for a field that contains the string "pH". The field is called extra.monitor_value_name. Examples of potential values are Temperature_ABC01, DO_ABC01, or pH_ABC01.

Kibana's Elasticsearch Query DSL does not seem to have a "contains string" so I need to custom make a query.

I am new to Query DSL, can you help me create the query?

Also, is it proper to call it Query DSL? I'm not even sure of proper wording.

like image 389
Intrastellar Explorer Avatar asked Mar 13 '19 15:03

Intrastellar Explorer


People also ask

Which query DSL is used to perform exact text match?

The match query is the standard query for performing a full-text search, including options for fuzzy matching.

What is DSL query?

Query DSL stands for Domain Specific Language. In elasticsearch, searching is performed using the search query, which is based on JSON. Elasticsearch provides full query DSL that helps to define queries. There are two clauses in elasticsearch that make a query, which are - 1.

How do I search for a query in Elasticsearch?

You can use the search API to search and aggregate data stored in Elasticsearch data streams or indices. The API's query request body parameter accepts queries written in Query DSL. The following request searches my-index-000001 using a match query. This query matches documents with a user.id value of kimchy .

For what purpose is query DSL used in Elasticsearch?

Elasticsearch provides a full Query DSL (Domain Specific Language) based on JSON to define queries. Think of the Query DSL as an AST (Abstract Syntax Tree) of queries, consisting of two types of clauses: Leaf query clauses.


2 Answers

Okay! Circling back with an answer to my own question.

My initial problem stemmed from not knowing about field_name vs field_name.keyword. Read here for info on keyword here: What's the difference between the 'field' and 'field.keyword' fields in Kibana?

Solution 1

Here's the query I ended up using. I used a regexp query. I found this article useful in figuring out syntax for the regexp:

{
  "query": {
    "regexp": {
      "extra.monitor_value_name.keyword": "pH.*"
    }
  }
}

Solution 2

Another way I could have filtered, without Query DSL was typing in a search field: extra.monitor_value_name.keyword:pH*. One interesting thing to note was the .keyword doesn't seem to be necessary with this method. I am not sure why.

like image 184
Intrastellar Explorer Avatar answered Nov 15 '22 07:11

Intrastellar Explorer


try this in filter using Elasticsearch Query DSL:

{
  "query": {
    "wildcard": {
      "extra.monitor_value_name": {
        "value": "pH.*"
      }
    }
  }
}
like image 25
Johnny Cage Avatar answered Nov 15 '22 09:11

Johnny Cage