From dd523b7d5c5dda356ac30ff98099a9f6f26d9ea8 Mon Sep 17 00:00:00 2001 From: Kevin_Zheng Date: Fri, 10 Mar 2017 10:57:02 +0800 Subject: [PATCH] Return simplified query result This patch added a boolean parameter 'simplified' for search, with this flag set, we only return the source data to caller, which they really care, projects like Nova can handle them easier than the nested data. Closes-Bug: #1671684 Change-Id: Id2d3b0a74a857ad98b4570c7ea794d2515f7d5ef --- searchlightclient/v1/search.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/searchlightclient/v1/search.py b/searchlightclient/v1/search.py index 8924f6b..66a82e4 100644 --- a/searchlightclient/v1/search.py +++ b/searchlightclient/v1/search.py @@ -39,6 +39,7 @@ class SearchManager(base.BaseManager): :param highlight: add an Elasticsearch highlight clause :param all_projects: by default searches are restricted to the current project unless all_projects is set + :param simplified: return only _source data """ search_params = {} for k, v in kwargs.items(): @@ -46,4 +47,12 @@ class SearchManager(base.BaseManager): 'limit', 'sort', '_source', 'highlight', 'all_projects'): search_params[k] = v resources = self._post('/v1/search', search_params) + + # NOTE: This could be done at the server side to reduce data + # transfer, since the data have been wrapped several times + # before transfer, and the data overhead is pretty small comparing + # to the data payload('_source'), it is done here for simplicity. + if 'simplified' in kwargs.keys() and kwargs['simplified']: + resources = [h['_source'] for h in resources.hits['hits']] + return resources