I am using Elasticsearch and AngularJS to build a small search application. I'm trying to use Angular UI Bootstrap Typeahead to implement an autocomplete feature using the http.get call for asynchronous results and am not exactly sure where to put it?.... still learning ES and Angular.
Where would I put this http.get call inside this js promise code?
http.get code:
return $http.get('localhost:9200/bigtestindex/doc/_search', {
params: {
"query": {
"match": {
"content.autocomplete": {
"query": query,
"default_operator": "and"
}
}
}
}
}),
Javascript promise code:
this.getSuggestions = function(query) {
var deferred = $q.defer();
var terms = query.split(' '),
baseTerms = terms.length === 1 ? '' : terms.slice(0, -1).join(' ') + ' ',
lastTerm = terms[terms.length - 1].toLowerCase();
esClient.search({
index: 'bigtestindex',
body: {
"query": {
"simple_query_string": {
"fields": ['title'],
"query": baseTerms + '(' + lastTerm + '|' + lastTerm + '*)',
"default_operator": "and"
}
},
"suggest": {
"text": query,
"phraseSuggestion": {
"phrase": {
"field": "title",
"direct_generator": [{
"field": "title",
"suggest_mode": "popular",
"min_word_length": 3,
"prefix_length": 2
}]
}
}
},
"size": 5,
"_source": ["content"]
}
}).then(function(es_return) {
deferred.resolve(es_return);
}, function(error) {
deferred.reject(error);
});
return deferred.promise;
};
I am pretty sure in goes in the body somewhere just not sure where... I can't get it to work.