Response filtering, exclude some fields by result

37 views
Skip to first unread message

Nikolay Nikolov

unread,
Feb 28, 2016, 12:12:01 PM2/28/16
to Elastica - Elasticsearch PHP Client
Hi, how can I do this with Elastica?

curl -XGET 'localhost:9200/_search?pretty&filter_path=hits.hits._source&_source=title' { "hits" : { "hits" : [ { "_source":{"title":"Book #2"} }, { "_source":{"title":"Book #1"} }, { "_source":{"title":"Book #3"} } ] } }

Thanks
Nik

ruflin

unread,
Feb 28, 2016, 2:21:47 PM2/28/16
to Elastica - Elasticsearch PHP Client
As this looks like a less typical query I would recommend to use the raw query option: http://elastica.io/example/raw-array-query.html

Nikolay Nikolov

unread,
Feb 29, 2016, 2:56:56 PM2/29/16
to Elastica - Elasticsearch PHP Client
This was only the example of this what I want to do. Are there function to make this over Elastica?

ruflin

unread,
Mar 1, 2016, 4:42:42 AM3/1/16
to Elastica - Elasticsearch PHP Client
Yes, see my link above. If there is no predefined query object, you can always use raw queries to map any possible request for elasticsearch.

Nikolay Nikolov

unread,
Mar 1, 2016, 11:12:11 AM3/1/16
to Elastica - Elasticsearch PHP Client
I understand, but when I start to use raw queries, I will not use the Elastica framework, because I can make an curl request by my self.

Is it possible to add this feature in the next version of Elastica? I think many of us will use it, because for example you can search in many fields but you would not to become all of this fields in the response. For my example, I am searching in the description of the job, but I would become only the title of the job as response. In this way I am reducing my response object.

ruflin

unread,
Mar 2, 2016, 2:18:00 AM3/2/16
to Elastica - Elasticsearch PHP Client
If you use raw queries you still get the response object from elastica.

More then happy to have this in one of the future release of Elastica (Pull requests are welcome ;-) ). I think what is not clear to me yet what the exact feature is here? Is it just additional query params and you left out the search query part above? Can you link to the docs from elasticsearch? Elastica mainly maps "elasticsearch" features and builds proxy functions around it.

Nikolay Nikolov

unread,
Mar 2, 2016, 8:46:29 AM3/2/16
to Elastica - Elasticsearch PHP Client
Great to hear this :-)

Yes the feature is to be able to set additional parameters to the search URL:

localhost:9200/_search?&filter_path=hits.hits._source&_source=title

In this way I can say which fields I want to have for the result and this will reduce a bunch of my response object. 

Thanks
Nikolay

ruflin

unread,
Mar 3, 2016, 8:22:25 AM3/3/16
to Elastica - Elasticsearch PHP Client
This is actually already implemented. When you use \Elastica\Search::search(...) you can pass your additional params as options array: http://elastica.io/api/classes/Elastica.Search.html#method_search
Reply all
Reply to author
Forward
0 new messages