Example Query for Documents Containing field a AND field b

Hello, Newbie here. I would like to query my index for all documents that must have field A AND field B. Ideally, I would like to be able to query on a list of fields using the AND operator. Meaning, all fields in the list must be in the document. However, through all of my searching/reading I can't find such an example. Can someone please help or provide an example, (Java API would be great)

Hi @trs80, Welcome the Elastic community.

I think you're looking for field exists query.

GET index_name/_search
{
  "query": {
    "bool": {
      "filter": [
        {
          "exists": {
            "field": "field_A"
          }
        },
        {
          "exists": {
            "field": "field_B"
          }
        }
      ]
    }
  }
}

Thank you @ashishtiwari1993. This is helpful. Any thoughts on how to do this for a list of fields? Thanks!

You need to add multiple exists object in filter query.