Elasticsearch in nodejs: get suggest's simple_phrase query values

I have such kind of index test

PUT test
{
  "settings": {
    "index": {
      "number_of_shards": 1,
      "analysis": {
        "analyzer": {
          "trigram": {
            "type": "custom",
            "tokenizer": "standard",
            "filter": ["lowercase","shingle"]
          },
          "reverse": {
            "type": "custom",
            "tokenizer": "standard",
            "filter": ["lowercase","reverse"]
          }
        },
        "filter": {
          "shingle": {
            "type": "shingle",
            "min_shingle_size": 2,
            "max_shingle_size": 3
          }
        }
      }
    }
  },
  "mappings": {
    "properties": {
      "word": {
        "type": "text",
        "fields": {
          "trigram": {
            "type": "text",
            "analyzer": "trigram"
          },
          "reverse": {
            "type": "text",
            "analyzer": "reverse"
          }
        }
      }
    }
  }
}

and want to take suggest.simple_phrase values by this way:

getElasticSearchResult: (_, params, context) =>
      new Promise((resolve, reject) => {
        const param: RequestParams.Search = {
          index: 'test',
          body: {
            suggest: {
              text: 'params.searchText',
              simple_phrase: {
                phrase: {
                  field: 'word.trigram',
                  size: 1,
                  gram_size: 3,
                  direct_generator: [
                    {
                      field: 'word.trigram',
                      suggest_mode: 'always',
                    },
                  ],
                  highlight: {
                    pre_tag: '<em>',
                    post_tag: '</em>',
                  },
                },
              },
            },
          },
        };
        client
          .search(param)
          .then((result: ApiResponse) => {
            resolve(result.body.suggest.simple_phrase);
            console.log('---- ', resolve(result.body));
          })
          .catch((err: Error) => {
            console.log(err);
            reject(err);
          });
      }).then(v => {
        return allRecords;
      }),
},

but result.body is undefined and why?

request comes correctly and result structure is also correct but inside everything is empty.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.