# How to make queryStringQuery?

**URL:** <https://discuss.elastic.co/t/how-to-make-querystringquery/179348>\
**Category:** Elasticsearch\
**Created:** [May 2, 2019, 11:20am UTC](https://discuss.elastic.co/t/how-to-make-querystringquery/179348 "2019-05-02T11:20:56Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aswini\_Kumar\_Rout](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aswini_kumar_rout/32/42165_2.png) [@Aswini\_Kumar\_Rout](https://discuss.elastic.co/u/Aswini_Kumar_Rout)\
**Post date:** [May 2, 2019, 11:20am UTC](https://discuss.elastic.co/t/how-to-make-querystringquery/179348/1 "2019-05-02T11:20:56Z")

</div>

Can anybody please help me to convert the below query to a queryStringQuery which I can execute in java by QueryStringQueryBuilder .

The Query:-

```auto
{
  "bool" : {
    "must" : [
      {
        "bool" : {
          "must" : [
            {
              "term" : {
                "languageId" : {
                  "value" : "2",
                  "boost" : 1.0
                }
              }
            },
            {
              "term" : {
                "storeId" : {
                  "value" : "2",
                  "boost" : 1.0
                }
              }
            }
          ],
          "adjust_pure_negative" : true,
          "boost" : 1.0
        }
      }
    ],
    "filter" : [
      {
        "bool" : {
          "adjust_pure_negative" : true,
          "boost" : 1.0
        }
      },
      {
        "bool" : {
          "should" : [
            {
              "range" : {
                "publish_date" : {
                  "from" : "2019-01-26T05:48:27Z",
                  "to" : null,
                  "include_lower" : true,
                  "include_upper" : true,
                  "boost" : 1.0
                }
              }
            },
            {
              "bool" : {
                "must_not" : [
                  {
                    "exists" : {
                      "field" : "publish_date",
                      "boost" : 1.0
                    }
                  }
                ],
                "adjust_pure_negative" : true,
                "boost" : 1.0
              }
            }
          ],
          "adjust_pure_negative" : true,
          "boost" : 1.0
        }
      },
      {
        "bool" : {
          "should" : [
            {
              "range" : {
                "publish_end_date" : {
                  "from" : null,
                  "to" : "2019-07-26T05:48:27Z",
                  "include_lower" : true,
                  "include_upper" : true,
                  "boost" : 1.0
                }
              }
            },
            {
              "bool" : {
                "must_not" : [
                  {
                    "exists" : {
                      "field" : "publish_end_date",
                      "boost" : 1.0
                    }
                  }
                ],
                "adjust_pure_negative" : true,
                "boost" : 1.0
              }
            }
          ],
          "adjust_pure_negative" : true,
          "boost" : 1.0
        }
      }
    ],
    "should" : [
      {
        "bool" : {
          "should" : [
            {
              "match_phrase_prefix" : {
                "name" : {
                  "query" : "spider",
                  "slop" : 0,
                  "max_expansions" : 50,
                  "boost" : 1.0
                }
              }
            },
            {
              "match_phrase_prefix" : {
                "category" : {
                  "query" : "spider",
                  "slop" : 0,
                  "max_expansions" : 50,
                  "boost" : 1.0
                }
              }
            }
          ],
          "adjust_pure_negative" : true,
          "boost" : 1.0
        }
      },
      {
        "bool" : {
          "adjust_pure_negative" : true,
          "boost" : 1.0
        }
      }
    ],
    "adjust_pure_negative" : true,
    "boost" : 1.0
  }
}

```

I want to execute this like below-

```auto
QueryStringQueryBuilder queryBuilder = QueryBuilders.queryStringQuery("The QUERY STRING");
		SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
		searchSourceBuilder.query(queryBuilder);
    	
		SearchRequest searchRequest = new SearchRequest();
		
		/ *****set the indices you want to search in***** /
		searchRequest.indices("content","a");
		searchRequest.source(searchSourceBuilder);
		
		try {
			SearchResponse response = client.search(searchRequest);
			System.out.println(response);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

```

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [May 2, 2019, 11:39am UTC](https://discuss.elastic.co/t/how-to-make-querystringquery/179348/2 "2019-05-02T11:39:33Z")

</div>

Why do you want to convert a complex query like this to a queryString query?  
I don't think it's doable. Or at least hardly doable.

---

<div class="post-metadata">

**Author:** ![Aswini\_Kumar\_Rout](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aswini_kumar_rout/32/42165_2.png) [@Aswini\_Kumar\_Rout](https://discuss.elastic.co/u/Aswini_Kumar_Rout)\
**Post date:** [May 2, 2019, 12:36pm UTC](https://discuss.elastic.co/t/how-to-make-querystringquery/179348/3 "2019-05-02T12:36:20Z")

</div>

Ok forget about that complected query I just want to implement this simple query but not getting any result:

```auto
QueryStringQueryBuilder queryBuilder = QueryBuilders.queryStringQuery(" (name:spider OR category:spider) AND storeId:2 AND languageId:2 ");
		SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
		searchSourceBuilder.query(queryBuilder);
    	
		SearchRequest searchRequest = new SearchRequest();
		
		/ *****set the indices you want to search in***** /
		searchRequest.indices("content","a");
		searchRequest.source(searchSourceBuilder);
		
		try {
			SearchResponse response = client.search(searchRequest);
			System.out.println(response);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

```

May be I am doing something wrong.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [May 2, 2019, 1:05pm UTC](https://discuss.elastic.co/t/how-to-make-querystringquery/179348/4 "2019-05-02T13:05:54Z")

</div>

> [@Aswini\_Kumar\_Rout](#):
>
> May be I am doing something wrong.

Probably. Does it work in Kibana dev console?

---

<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:** [May 30, 2019, 1:05pm UTC](https://discuss.elastic.co/t/how-to-make-querystringquery/179348/5 "2019-05-30T13:05:57Z")

</div>

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