2

My indexed Elasticsearch documents include many fields. I've been using match_all query to get results. There are a few fields I'd like to exclude from match_all, is this possible?

Christophe Roussy
  • 16,299
  • 4
  • 85
  • 85
Daniel Kobe
  • 9,376
  • 15
  • 62
  • 109
  • Looks like a duplicate of http://stackoverflow.com/questions/18220883/is-there-a-way-to-exclude-a-field-in-an-elasticsearch-query, but the other one is from 2013 – Christophe Roussy May 30 '16 at 13:42

3 Answers3

1

For this question I will give you the example

GET index_name/index_type/_search
{
  "_source": {

  "exclude": [
    ]
  },
  "query": {
    "match_all": {}
  }
}
0

In Elasticsearch you can use partial fields to filter fields.

Example:

{
    "query": {
        "match_all": {}
    },
    "partial_fields": {
        "partial1": {
            "exclude": ["excludeField1", "excludeField2"]
        }
    }
}
chengpohi
  • 14,064
  • 1
  • 24
  • 42
  • 2
    How to do the same in ES6. The above code does not works for me. it gives **[query_string] unknown token [START_OBJECT] after [partial_fields]** – Richa Sinha Oct 10 '18 at 10:41
0

With ElasticSearch 2.x, you can use source filtering, example:

{
    "_source": {
        "include": [ "obj1.*", "obj2.*" ],
        "exclude": [ "*.description" ]
    },
    "query" : {
        "term" : { "user" : "kimchy" }
    }
}

For a GET request you may also pass it via the url.

Christophe Roussy
  • 16,299
  • 4
  • 85
  • 85