Abhilash
Abhilash

Reputation: 895

Elastic Search Query builder

I have an elastic search json response like:

"source": {
lastupdate_es: "2016-01-11T11:22:49.800Z",
prod_id: [
"prod12345"
],
price: [
{
price_list: "ADomain",
list_price: 31.67
},
{
price_list: "ADomain",
list_price: 760
},
{
price_list: "ADomain",
list_price: 31.67
},
{
price_list: "BDomain",
list_price: 760
},
{
price_list: "BDomain",
list_price: 29.66
},
{
price_list: "CDomain",
list_price: 710
},

],
sku_id: "sku123445"
}

I need a query to filter records, the SQL query would be something like "select * from table where prop_id='product id' and price_list like '%Domain'. How can we create an elastic query to achieve this?

Upvotes: 0

Views: 197

Answers (1)

Sergej Schelle
Sergej Schelle

Reputation: 420

If you like SQL syntax, that may be a solution for you.

Use something like this

POST /index_name/table/_search

{
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "prod_id": "prod12345"
          },
          "regexp": {
            "price_list": ".Domain"
          }
        }
      ]
    }
  }
}

to perform your query in elasticsearch directly.

Upvotes: 1

Related Questions