Yuki Takei 4 лет назад
Родитель
Сommit
bc548b2406
1 измененных файлов с 9 добавлено и 6 удалено
  1. 9 6
      packages/app/src/server/service/search-delegator/elasticsearch.ts

+ 9 - 6
packages/app/src/server/service/search-delegator/elasticsearch.ts

@@ -614,22 +614,25 @@ class ElasticsearchDelegator implements SearchDelegator<Data> {
    * }
    * }
    */
    */
   async searchKeyword(query): Promise<IFormattedSearchResult> {
   async searchKeyword(query): Promise<IFormattedSearchResult> {
+
     // for debug
     // for debug
     if (process.env.NODE_ENV === 'development') {
     if (process.env.NODE_ENV === 'development') {
+      logger.debug('query: ', { query });
+
       const { body: result } = await this.client.indices.validateQuery({
       const { body: result } = await this.client.indices.validateQuery({
+        index: query.index,
+        type: query.type,
         explain: true,
         explain: true,
         body: {
         body: {
           query: query.body.query,
           query: query.body.query,
         },
         },
       });
       });
-      logger.debug('ES returns explanations: ', result.explanations);
+      // for debug
+      logger.debug('ES result: ', result);
     }
     }
 
 
     const { body: result } = await this.client.search(query);
     const { body: result } = await this.client.search(query);
 
 
-    // for debug
-    logger.debug('ES result: ', result);
-
     const totalValue = this.isElasticsearchV6 ? result.hits.total : result.hits.total.value;
     const totalValue = this.isElasticsearchV6 ? result.hits.total : result.hits.total.value;
 
 
     return {
     return {
@@ -665,9 +668,9 @@ class ElasticsearchDelegator implements SearchDelegator<Data> {
     // eslint-disable-next-line prefer-const
     // eslint-disable-next-line prefer-const
     let query = {
     let query = {
       index: this.aliasName,
       index: this.aliasName,
+      _source: fields,
       body: {
       body: {
         query: {}, // query
         query: {}, // query
-        _source: fields,
       },
       },
     };
     };
 
 
@@ -687,7 +690,7 @@ class ElasticsearchDelegator implements SearchDelegator<Data> {
     // default sort order is score descending
     // default sort order is score descending
     const sort = ES_SORT_AXIS[sortAxis] || ES_SORT_AXIS[RELATION_SCORE];
     const sort = ES_SORT_AXIS[sortAxis] || ES_SORT_AXIS[RELATION_SCORE];
     const order = ES_SORT_ORDER[sortOrder] || ES_SORT_ORDER[DESC];
     const order = ES_SORT_ORDER[sortOrder] || ES_SORT_ORDER[DESC];
-    query.body.sort = { [sort]: { order } };
+    query.sort = { [sort]: { order } };
   }
   }
 
 
   convertSortQuery(sortAxis) {
   convertSortQuery(sortAxis) {