0

I have this code :

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

for me to make a search I need to add a title and a desc , but I wish to search even if one is not present, meaning I want either title or desc, does anyone know the correct syntax?

Alexander
  • 1,288
  • 5
  • 19
  • 38

1 Answers1

1

Ok I found the answer, instead of must we can write should, and it will work:

let jobs = await client.search({
      index: 'something',
      type: 'doc',
      body: {
        query: {
          bool: {
            should: [
              {
                match: {
                  title: `test`
                }
              },
              {
                match: {
                  desc: `test`
                }
              }
            ]
          }
        }
      }
    });
Alexander
  • 1,288
  • 5
  • 19
  • 38