I am able to query an index in elasticsearch. And, now I want to narrow down the data to some specific fields. But, I am keep getting errors.
Here is my query:
es = Elasticsearch(hosts="myhost", "port":0000)
search_body={
"bool":{
"filter":[
{"exists": {"field": "customer_name"}},
{"match_phrase": {"city": "chicago"}},
]
}
}
results = es.search(index="some_index", query=search_body)
I am easily able to get results upto this point. But, since the returned has so many fields, I want to retrieve only specific fields before converting it into a dataframe. I can convert it into a dataframe and then filter, but that is not optimal.
I tried adding _source
and field
methods as:
search_body={
"bool":{
"filter":[
{"exists": {"field": "customer_name"}},
{"match_phrase": {"city": "chicago"}},
]
},
"_source":{"fields": {"includes":["customer_name", "city", "company", "company_address"] }}
}
and other variants like,
"fields": {"includes":["customer_name", "city", "company", "company_address"] }
# or
"_source":{"includes":["customer_name", "city", "company", "company_address"] }
# and several others.
I keep getting error:
raise HTTP_EXCEPTIONS.get(status_code, TransportError)(
elasticsearch.exceptions.RequestError: RequestError(400, 'parsing_exception', '[bool] malformed query, expected [END_OBJECT] but found [FIELD_NAME]')
I followed:
- https://www.elastic.co/guide/en/elasticsearch/reference/current/search-fields.html
- https://www.elastic.co/guide/en/elasticsearch/reference/current/search-fields.html#source-filtering
- several stackoverflow answers
- even tried named query
What am I missing here?