
On Wed, Dec 02, 2020 at 08:05:13PM +0800, Cao Xueliang wrote:
On Wed, Dec 02, 2020 at 07:22:56PM +0800, Li Yuanchao wrote:
Query all testboxes from es, and return a non repetitive list
Signed-off-by: Li Yuanchao <lyc163mail@163.com> --- src/lib/web_backend.rb | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)
diff --git a/src/lib/web_backend.rb b/src/lib/web_backend.rb index e548d61..fe9545f 100644 --- a/src/lib/web_backend.rb +++ b/src/lib/web_backend.rb @@ -435,3 +435,31 @@ def template_body(request_body) formatter = FormatEchartData.new(compare_results, request_body) formatter.format_for_echart.to_json end + +def search_testboxes + query = { size: 0, aggs: { testboxes: { terms: { size: 10000, field: 'testbox' } } } } + buckets = es_query(query)['aggregations']['testboxes']['buckets'] + testboxes = [] + buckets.each_index do |index| + testboxes[index] = buckets[index]['key'] + end + return testboxes, testboxes.length +end + +def testboxes_body + testboxes, total = search_testboxes + { + total: total, + testboxes: testboxes + }.to_json +end + +def query_testboxes
You can write the api in a independent file.
Here is not api. There is another file for api, this file is for implementation. Thanks, Yuanchao