您好我是ElasticSearch的新手,我正在努力从ElasticSearch的响应中删除所有额外的字段。请参阅以下回复:
"report": {
"unique_users": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": 1234,
"doc_count": 2,
"user_details": {
"hits": {
"total": 2,
"max_score": 1.4E-45,
"hits": [
{
"_index": "orders-test",
"_type": "order",
"_id": "2",
"_score": 0.0,
"_source": {
"customer_email": "reba_dickens@blick.name",
"customer_phone": "476.824.4998 x498",
"customer_name": "Mohammed Abernathy"
}
}
]
}
}
},
{
"key": 5678,
"doc_count": 1,
"user_details": {
"hits": {
"total": 1,
"max_score": 1.4E-45,
"hits": [
{
"_index": "orders-test",
"_type": "order",
"_id": "1",
"_score": 0.0,
"_source": {
"customer_email": "yolanda.batz@ruel.biz",
"customer_phone": "1-715-183-8343 x026",
"customer_name": "Richie Tillman II"
}
}
]
}
}
}
]
}
}
上面你可以看到响应中还有一些其他字段,如_index,_type,_score,max_score等。我已经按照ElasticSearch response_filtering指南删除了这些字段,但它不适用于我。我还将filter_path参数传递给请求0.0.0.0:5000/v4/reports/user.json?filter_path=unique_users,unique_users.user_details.hits.hits._source,但没有得到任何响应。我使用下面的函数来处理Elasticsearch查询。
def query(options = {})
aggregations = {}
buckets = {}
buckets_for_unique_users buckets, aggregations
buckets_for_new_users buckets, aggregations
buckets_for_high_rollers buckets, aggregations
filters = []
filters << time_filter(options)
filters << restaurant_filter(options) if options[:restaurant_id]
filters << channel_filter(options) if options[:channel_id]
query = {
query: { bool: { filter: filters } },
aggregations: buckets
}
query
end
有谁能告诉我我在哪里做错了。
答案 0 :(得分:0)
使用&#34; _source&#34;使用您在请求中所需的属性。这将有助于您只获取指定的字段。
https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-source-filtering.html