I am using elasticsearch dsl to search on elasticsearch : https://elasticsearch-dsl.readthedocs.org/en/latest/
How can i filter specific fields while making a search query:
I know its supported in elasticsearch: https://www.elastic.co/guide/en/elasticsearch/reference/1.4/search-request-fields.html
Just dont know how to do the same in Elasticsearch-dsl
When you have your Search
object you can call the .fields()
function on it and specify which fields you want to return:
s = search.Search()
s = s.fields(["field1", "field2"])
...
It's not explicitly mentioned in the documentation, but you can see the fields
function in the source for the search.py
file and some test cases for the fields
function
UPDATE
From ES 2.x onwards, the fields()
method has been renamed to source()
In elasticsearch-dsl version 6.x.x fields()
is deprecated and result with exception.
use source(fields=None, **kwargs)
in order to projection
columns
e.g.
s = Search()
s = s.source(["field1", "field2"])
s = Search()
s = s.source(include=['obj1.*'], exclude=["*.description"])
s = Search()
s = s.source(include=['obj1.*']).source(exclude=["*.description"])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With