Browse Source

Ensure backword compatibility for ES6 when using max_analyzed_offset

Taichi Masuyama 3 years ago
parent
commit
5153f1b0aa
1 changed files with 4 additions and 1 deletions
  1. 4 1
      packages/app/src/server/service/search-delegator/elasticsearch.ts

+ 4 - 1
packages/app/src/server/service/search-delegator/elasticsearch.ts

@@ -943,7 +943,6 @@ class ElasticsearchDelegator implements SearchDelegator<Data, ESTermsKey, ESQuer
 
   appendHighlight(query) {
     query.body.highlight = {
-      max_analyzed_offset: 1000000 - 1, // Set the query parameter [max_analyzed_offset] to a value less than index setting [1000000] and this will tolerate long field values by truncating them.
       fields: {
         '*': {
           fragment_size: 40,
@@ -953,6 +952,10 @@ class ElasticsearchDelegator implements SearchDelegator<Data, ESTermsKey, ESQuer
         },
       },
     };
+
+    if (!this.isElasticsearchV6) {
+      query.body.highlight.max_analyzed_offset = 1000000 - 1; // Set the query parameter [max_analyzed_offset] to a value less than index setting [1000000] and this will tolerate long field values by truncating them.
+    }
   }
 
   async search(data: SearchableData<ESQueryTerms>, user, userGroups, option): Promise<ISearchResult<unknown>> {