4

I am new in elasticsearch. I want elasticsearch result be like following sql query,

select distinct(car_name) from car_master where car_name like '%SUV%'

I am getting result by doing:

{ "query": {
    "query_string": {
    "fields" : ["car_name"],
    "query": "*SUV*"
    }
  }
}

but I want distinct records.

1 Answer 1

3

You are almost there, you simply need to add a terms aggregation on the car_name field:

{ 
  "query": {
    "query_string": {
    "fields" : ["car_name"],
    "query": "*SUV*"
    }
  },
  "aggs": {
    "cars": {
      "terms": {
        "field": "car_name"
      }
    }
  }
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.