ElasticSearch Java API "Should" Array


(Yeikel) #1

I am trying to convert the following query :

GET /consumer/_search
{
  "query": {
    "bool": {
      "should": [
        {
          "bool": {
            "must": [
              {
                "match": {
                  "first_name": {
                    "query": "Peter"
                  }
                }
              },
              {
                "match": {
                  "last_name": {
                    "query": "Parker"
                  }
                }
              }
            ]
          }
        },
        {
          "bool": {
            "must": [
              {
                "match": {
                  "first_name": {
                    "query": "Parker"
                  }
                }
              },
              {
                "match": {
                  "last_name": {
                    "query": "Peter"
                  }
                }
              }
            ]
          }
        }
      ]
    }
  }
}

I tried the following :

 query = QueryBuilders.boolQuery()
	.should(QueryBuilders.boolQuery()
 	.must(QueryBuilders.matchQuery("first_name", "Peter").type(null))
	.must(QueryBuilders.matchQuery("last_name""Parker").type(null))
	.must(QueryBuilders.matchQuery("first_name","Parker").type(null))
	.must(QueryBuilders.matchQuery("last_name","Peter").type(null)))

But that's obviously not the same.

I also tried :

 .should(QueryBuilders.boolQuery()
 .must(QueryBuilders.matchQuery("first_name", "Peter").type(null))
 .must(QueryBuilders.matchQuery("last_name", "Parker").type(null))
 .should(QueryBuilders.boolQuery()
 .must(QueryBuilders.matchQuery("first_name", "Parker").type(null))
 .must(QueryBuilders.matchQuery("last_name", "Peter").type(null))))

But it did not work as well

Thank you!


(system) #2