使用具有多个字段的 elasticsearch js 进行搜索

Ale*_*x K 2 node.js elasticsearch

大家好,我有这个代码:

let test = await client.search({
      index: 'test',
      type: 'doc',
      body: {
        query: {
          match: {
            title: 'something',
          }
        }
      }
    });
Run Code Online (Sandbox Code Playgroud)

此代码通过 1 个查询进行搜索,即 title: 'something' ,但我想将其更改为使用多个键进行搜索,例如:

 let test = await client.search({
          index: 'test',
          type: 'doc',
          body: {
            query: {
              match: {
                title: 'something',
                desc: 'some Qualifications'
              }
            }
          }
        });
Run Code Online (Sandbox Code Playgroud)

但是这段代码不起作用,我找不到任何可以这样工作的东西,有人可以帮忙吗?

Val*_*Val 5

您需要match使用bool/must查询组合所有查询,如下所示:

 let test = await client.search({
      index: 'test',
      type: 'doc',
      body: {
        query: {
          bool: {
            must: [
              {
                match: {
                  title: 'something',
                }
              },
              {
                match: {
                  desc: 'some Qualifications',
                }
              }
            ]
          }
        }
      }
    });
Run Code Online (Sandbox Code Playgroud)