While querying Elasticsearch, it’s a good practice to restrict your search results to only the fields you need.
To include only specific fields in an Elasticsearch query, use source filtering:
GET /_search
{
"_source": {
"include": ["title", "country"]
},
"query" : {
"term" : { "country" : "france" }
}
}
You can also do source filtering using a GET
parameter.
curl "localhost:9200/<index>/_doc/1?_source_includes=title,country"
NOTE: you can also exclude specific fields in a search response.
Elasticsearch can have a steep learning curve. If you're looking for a fast but easier-to-use alternative,
take a look at Typesense.