最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

如何使用多个变量创建搜索并使其变为非强制性

运维笔记admin17浏览0评论

如何使用多个变量创建搜索并使其变为非强制性

如何使用多个变量创建搜索并使其变为非强制性

我有此代码:

let jobs = await client.search({
      index: 'something',
      type: 'doc',
      body: {
        query: {
          bool: {
            must: [
              {
                match: {
                  title: `test`
                }
              },
              {
                match: {
                  desc: `test`
                }
              }
            ]
          }
        }
      }
    });

为了进行搜索,我需要添加一个标题和一个desc,但是即使没有一个标题,我也希望进行搜索,这意味着我想要标题或desc,有人知道正确的语法吗?

回答如下:

好吧,我找到了答案,而不是我们必须写的应该的,它会起作用:

let jobs = await client.search({
      index: 'something',
      type: 'doc',
      body: {
        query: {
          bool: {
            should: [
              {
                match: {
                  title: `test`
                }
              },
              {
                match: {
                  desc: `test`
                }
              }
            ]
          }
        }
      }
    });
发布评论

评论列表(0)

  1. 暂无评论