为什么elasticsearch可以搜索空间?

vngu2lb8  于 5个月前  发布在  ElasticSearch
关注(0)|答案(1)|浏览(70)
const searchParams = {
        index: "products",
        body: {
          from: offset,
          size: limit,
          query: {
            bool: {
              must: {
                term: {
                  name: `*${fullTextSearch}*`,
                },
              },
            },
          },
        },
      };

字符串
我有一个这样的searchParams,但是当name=“gold ring”时。它没有显示任何数据。但是如果name输入没有空格name =“gold”,它就工作了。
为什么elasticsearch可以搜索空间

k4aesqcs

k4aesqcs1#

我的猜测是nametext类型,因此它被分析为token。使用term查询搜索不会分析输入文本,而是搜索可能没有name字段包含的确切值gold ring
但是,如果您将查询更改为使用match而不是term,您应该会看到结果。您还应该删除前导和结尾通配符:

const searchParams = {
    index: "products",
    body: {
      from: offset,
      size: limit,
      query: {
        bool: {
          must: {
            match: {                       <---- change this
              name: `${fullTextSearch}`,   <---- change this
            },
          },
        },
      },
    },
  };

字符串

相关问题