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?
Asked
Active
Viewed 4,870 times
2
-
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 Answers
1
For this question I will give you the example
GET index_name/index_type/_search
{
"_source": {
"exclude": [
]
},
"query": {
"match_all": {}
}
}

KARTHEEK GUMMALURI
- 347
- 2
- 12
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
-
2How 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