From fd1002757bcfefbf65a3a21f973202060b378581 Mon Sep 17 00:00:00 2001 From: Froilan Irizarry Date: Sun, 19 Aug 2018 20:17:26 -0400 Subject: [PATCH 1/3] Removed index.mapping.total_fields.limit from repo index settings --- indexes/repo/settings.json | 1 - 1 file changed, 1 deletion(-) diff --git a/indexes/repo/settings.json b/indexes/repo/settings.json index 37af98ba..25611df0 100644 --- a/indexes/repo/settings.json +++ b/indexes/repo/settings.json @@ -1,5 +1,4 @@ { - "index.mapping.total_fields.limit": 2000, "analysis": { "filter": { "english_stop": { From bc0e932d51f9012762e29a8fba7de236376e186d Mon Sep 17 00:00:00 2001 From: Froilan Irizarry Date: Sun, 19 Aug 2018 20:33:32 -0400 Subject: [PATCH 2/3] Changed elasticsearch body construction - The query body has been simplified to use just the multi_match query with any filters that are passed in the query paramaters - the over use of bool, should, and must queries was removed. This was throwing the _score result off by making elasticsearch aggregate scores in a erroneos way. Multi_match query now has the type (best_match) explicit. More testing with over types could help improve the search results. The name field is given the highest weight followed by the fulltext analyzed version of itself. This change is focused on the repos index. It might be good to review the search being done with the terms index --- services/searcher/index.js | 51 ++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 30 deletions(-) diff --git a/services/searcher/index.js b/services/searcher/index.js index 8533e178..285d9741 100644 --- a/services/searcher/index.js +++ b/services/searcher/index.js @@ -100,32 +100,22 @@ class Searcher { body.query("bool", "should", query); } - _addFullTextQuery(body, queryParams) { - if (queryParams.q) { - // need to nest `_fulltext` query as a "must" - let ftBody = new Bodybuilder(); - - ftBody.query("bool", "should", { - "multi_match": { - "query": queryParams.q, - "fields": [ - "name^10", - "name._fulltext^10", - "description^4", - "agency.acronym^5", - "agency.name^5", - "agency.name._fulltext^5", - "permissions.usageType^3", - "tags", - "tags._fulltext", - "languages", - "languages._fulltext" - ] - } - }); - - body.query("bool", "must", ftBody.build("v2")["query"]); - } + _addFullTextQuery(body, searchQuery) { + const searchFields = [ + "name^10", + "name._fulltext^5", + "description^2", + "agency.acronym", + "agency.name^5", + "agency.name._fulltext", + "permissions.usageType", + "tags^3", + "tags._fulltext", + "languages^3", + "languages._fulltext" + ]; + + body.query("multi_match", 'fields', searchFields, {"query": searchQuery}, {"type": "best_fields"}); } _addStringFilter(body, field, filter) { @@ -236,6 +226,7 @@ class Searcher { * @param {any} queryParams The query parameters a user is searching for */ _addSortOrder(body, queryParams) { + body.sort('_score', queryParams['sort'] || 'desc'); body.sort('score', 'desc'); if(queryParams['sort']) { const sortValues = []; @@ -263,19 +254,19 @@ class Searcher { body.sort(sortField, 'asc'); } }); - } else { - body.sort('_score', queryParams['sort'] || 'desc'); } } _searchReposQuery(queryParams) { let body = new Bodybuilder(); + if(queryParams.q) { + this._addFullTextQuery(body, queryParams.q); + } this._addFieldFilters(body, queryParams); this._addSizeFromParams(body, queryParams); - this._addIncludeExclude(body, queryParams); - this._addFullTextQuery(body, queryParams); + this._addIncludeExclude(body, queryParams); this._addSortOrder(body, queryParams); let query = body.build("v2"); From af2fd37c5bd4d2fe3230269823005423e189e87c Mon Sep 17 00:00:00 2001 From: Froilan Irizarry Date: Mon, 20 Aug 2018 00:48:58 -0400 Subject: [PATCH 3/3] Change match query to match_phrase - This makes the query compatible with versions 2.4, 5.x, and 6.x --- services/searcher/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/searcher/index.js b/services/searcher/index.js index 285d9741..242db4c0 100644 --- a/services/searcher/index.js +++ b/services/searcher/index.js @@ -313,7 +313,7 @@ class Searcher { // add query terms (boost when phrase is matched) if (queryParams.term) { body.query("match", "term_suggest", queryParams.term); - body.query("match", "term_suggest", { query: queryParams.term, type: "phrase" }); + body.query("match_phrase", "term_suggest", { query: queryParams.term }); } // set the term types (use defaults if not supplied)