Difference between filter_path and _source_include?

(Henrik Östman) #1

Currently I have made two different APIs in my application, one does a Search against Elastic Search and the other one does a Template Search. In the first one I use _source_include to let the client specify which field in the hits they are interested in, and it's working great!

The other API that using searchTemplate can't use _source_include since that function is only available for standard search (https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/api-reference.html#api-search), the searchTemplate is much slimmer (https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/api-reference.html#api-searchtemplate). But there is a filterPath-property that seems to do the same thing and that is available for all query-command as I understand it: https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/api-conventions.html. What is the difference between them? Could we not just use filterPath everywhere and throw _source_include away? Unfortunately I can't get filterPath to work, it gives me everything and not just those properties that I'm trying to filter out. I there something I'am doing something wrong?

2015-10-09T11:17:21.120Z: 2015-10-09T11:17:21.118Z - debug: [elasticSearch] starting request
{ method: 'POST',
path: '/test2_content/content/_search/template',
{ template: { id: 'test2.content.clusterTemplate' },
params: { } },
{ search_type: 'query_then_fetch',
filter_path: 'payload.version',
explain: false,
from: 0,
size: 10 } }

Running Elastic Search 1.7
Javascript library https://github.com/elastic/elasticsearch-js version 8.2.0 with API-version 1.7


(system) #2