# Setting default operator to AND in elasticsearch when using SearchSourceBuilder and XContentParser

**URL:** <https://discuss.elastic.co/t/setting-default-operator-to-and-in-elasticsearch-when-using-searchsourcebuilder-and-xcontentparser/284326>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [September 15, 2021, 7:32pm UTC](https://discuss.elastic.co/t/setting-default-operator-to-and-in-elasticsearch-when-using-searchsourcebuilder-and-xcontentparser/284326 "2021-09-15T19:32:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![taugusti](https://avatars.discourse-cdn.com/v4/letter/t/8dc957/32.png) [@taugusti](https://discuss.elastic.co/u/taugusti)\
**Post date:** [September 15, 2021, 7:32pm UTC](https://discuss.elastic.co/t/setting-default-operator-to-and-in-elasticsearch-when-using-searchsourcebuilder-and-xcontentparser/284326/1 "2021-09-15T19:32:55Z")

</div>

I have the below sample code to query elasticsearch. It receives the user query and uses XContentParser and SearchSourceBuilder. I don't want to tweak a lot on the existing code as it is has been in production for a while. I would like to change the default operator from "OR" to "AND" so we get more meaningful messages. I couldn't find a way to set the default operator in this scenario. Any help apprecaited

```auto
String[] indicesArray={"index1","index2"};
String fullQueryJson={"query":{"nested":{"path":"_ROOT","query":{"query_string":{"query":"_ROOT.LATEST.FULL_NAME:John Mary C"}}}},"_source":["FULL_NAME","TEXT_MSG","USER_NAME"],"size":9010}

SearchSourceBuilder accessSearchSource = new SearchSourceBuilder();
final SearchModule searchModule = new SearchModule(Settings.EMPTY, false, Collections.emptyList());
final XContentParser fullQueryJsonParser = XContentFactory.xContent(XContentType.JSON)
                    .createParser(new NamedXContentRegistry(searchModule.getNamedXContents()), LoggingDeprecationHandler.INSTANCE, fullQueryJson);
accessSearchSource.parseXContent(fullQueryJsonParser);
SearchRequest request=new SearchRequest(indicesArray);
request.source(accessSearchSource);
esClient.search(request);

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [October 13, 2021, 7:33pm UTC](https://discuss.elastic.co/t/setting-default-operator-to-and-in-elasticsearch-when-using-searchsourcebuilder-and-xcontentparser/284326/2 "2021-10-13T19:33:40Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
