2

Hi guys I have this code :

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

this code is searching by 1 query which is title: 'something' , but I want to change it to search with multiple keys, for example:

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

but this code doesn't work and I can't find anything that will work like that, can anyone help?

1 Answer 1

6

You need to combine all the match queries using a bool/must query, like this:

 let test = await client.search({
      index: 'test',
      type: 'doc',
      body: {
        query: {
          bool: {
            must: [
              {
                match: {
                  title: 'something',
                }
              },
              {
                match: {
                  desc: 'some Qualifications',
                }
              }
            ]
          }
        }
      }
    });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.