How to represent query_string in java scripts


(soumya1986) #1

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.
To view this discussion on the web visit 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.


(Binh Ly) #2

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.
To view this discussion on the web visit 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.


(system) #3