From 674dddca8ae4b7718d6ae45acc72a8afd2f96dd0 Mon Sep 17 00:00:00 2001 From: Mark Beamer Jr Date: Thu, 8 Mar 2018 22:09:48 -0500 Subject: [PATCH] updated search query for elasticsearch. value is stored as a nested object in the elastic document. Therefore to query fields at that level or lower, a nested query is required. --- server/controllers/lighthouse.js | 41 +++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/server/controllers/lighthouse.js b/server/controllers/lighthouse.js index fbdf141..404362e 100644 --- a/server/controllers/lighthouse.js +++ b/server/controllers/lighthouse.js @@ -26,6 +26,45 @@ function getResults (input) { index : 'claims', _source: ['name', 'value', 'claimId'], body : { + 'query': { + 'bool': { + 'should': [ + { + 'match': { + 'name^100': '*' + input.s.trim() + '*', + }, + }, + { + 'nested': { // Need nested query because value is a nested object on the elastic document + 'path' : 'value', + 'query': { + 'bool': { + 'should': [ + { + 'match': { + 'value.stream.metadata.title': '*' + input.s.trim() + '*', + }, + }, + { + 'match': { + 'value.stream.metadata.author': '*' + input.s.trim() + '*', + }, + }, + { + 'match': { + 'value.stream.metadata.description': '*' + input.s.trim() + '*', + }, + }, + ], + }, + }, + }, + }, + ], + }, + }, + }, + /* body : { 'query': { 'bool': { 'must': { @@ -43,7 +82,7 @@ function getResults (input) { }, size: input.size, from: input.from, - }, + }, */ }); }