# How to represent query\_string in java scripts

**URL:** <https://discuss.elastic.co/t/how-to-represent-query-string-in-java-scripts/15826>\
**Category:** Elasticsearch\
**Created:** [February 15, 2014, 10:02pm UTC](https://discuss.elastic.co/t/how-to-represent-query-string-in-java-scripts/15826 "2014-02-15T22:02:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![soumya1986](https://avatars.discourse-cdn.com/v4/letter/s/6a8cbe/32.png) [@soumya1986](https://discuss.elastic.co/u/soumya1986)\
**Post date:** [February 15, 2014, 10:02pm UTC](https://discuss.elastic.co/t/how-to-represent-query-string-in-java-scripts/15826/1 "2014-02-15T22:02:09Z")

</div>

I am using AngularJS and ElasticJS for querying Elasticsearch.  
For the normal query given below, I have been able to write the  
corresponding script provided below the query

QUERY

{  
"query": {  
"match": {  
"\_all": {  
"query": "India Delhi",  
"operator": "and"  
}  
}  
}  
}

SCRIPT

myServices.factory('searchService', ['es', function(es) {  
return {  
textSearch: function(query){  
return es.search({  
index: 'country',  
type: 'state',  
q: query,  
defaultOperator: 'AND'  
})  
}  
};  
}]);

Now I have written a query\_string that works over multiple queries

{  
"size": 10,  
"query": {  
"query\_string" : {  
"query": "India Delhi",  
"fields": ["Country","State", "City"] ,  
"default\_operator": "AND"

}  
}  
}

How to represent the above query in javascript function ?

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/753c6687-3d91-4084-809c-5bbf034b12ac%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/753c6687-3d91-4084-809c-5bbf034b12ac%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Binh\_Ly](https://avatars.discourse-cdn.com/v4/letter/b/ce7236/32.png) [@Binh\_Ly](https://discuss.elastic.co/u/Binh_Ly)\
**Post date:** [February 19, 2014, 12:35am UTC](https://discuss.elastic.co/t/how-to-represent-query-string-in-java-scripts/15826/2 "2014-02-19T00:35:35Z")

</div>

Should be roughly like this:

```
var q = {
  query: {
    "query_string": {
      "query": "blah",
      "fields": ["blah"],
      "default_operator": "AND"
    }
  }
};

client.search({
  index: 'blah_index',
  size: 1,
  body: q
})

```

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/660d59b7-1446-4fad-8241-4178fe575ad4%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/660d59b7-1446-4fad-8241-4178fe575ad4%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:** [July 6, 2017, 1:49am UTC](https://discuss.elastic.co/t/how-to-represent-query-string-in-java-scripts/15826/3 "2017-07-06T01:49:15Z")

</div>


