Get /myindex/_search - return just 1 or 2 Fields not the whole Bucket or Document

Hi all,
im stuck in how to use the search in right way.

What I did to get all out of my Index:

PUT /myindex/_settings
{ "index" : { "max_result_window" : 100000 } }

Now with following GET Request I can show all the index entries = Check

GET /myindex/_search
{
  "size": 50000,
  "aggs": {
    "allEntries": {
      "terms": {
        "field": "Nr.keyword"
      }
    }
  }
}

The result is as json with more then 3milion lines...wow...ok

What I want is a result that shrinked down to just show me the 2 fields :
"Nr.keyword"
"Nr_alternate.keyword"
At least around 15000 entries
However, I do not want all the other fields around so how can I get just 1 or 2 fields as json result?

Thanks and Brgds

Hi!

Of course you can get just 1 or 2 fields in the result! You can use a source-filter as described here.

Your query then will look something like this:

GET /myindex/_search
{
  "size": 50000,
  "aggs": {
    "allEntries": {
      "terms": {
        "field": "Nr.keyword"
      }
    }
  },"_source": ["Nr.keyword", "Nr_alternate.keyword"]
}

or whichever fields you want to have returned. Just put them in the array...

1 Like

Oh man you safed my life :slightly_smiling_face:
Thanks for your fast response...

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.