Leigh
Leigh

Reputation: 23

Is it possible to return a specific field when running a query in sense for elasticsearch

I have loaded some data into elasticsearch and written a query against the data however the results contain all of the data for the matching queries. Is it possible to filter the results to show a particular field?

Example Query to find all records for a specific country but to return a list of registration numbers.

All the data is available elasticsearch however I get a full json record back for each match.

I'm running this query in SENSE (within Kibana 4.5.0).

The query is...

GET _search
{
  filter_path=reg_no.*,
    "fields" : ["reg_no"],
    "query" : {
        "fields" : ["country_cd", "oprg_stat"],
        "query" : "956 AND 9074"
      }
}

If I remove the two lines

filter_path=reg_no.*,
"fields" : ["reg_no"],

the query runs but brings back all the data.

Upvotes: 0

Views: 466

Answers (1)

Val
Val

Reputation: 217474

Try this query:

POST _search
{
  "_source": [
    "reg_no"
  ],
  "query": {
    "bool": {
      "filter": [
        {
          "term": {
            "country_cd": "956"
          }
        },{
          "term": {
            "oprg_stat": "9074"
          }
        }
      ]
    }
  }
}

Upvotes: 1

Related Questions