我试图在我的elasticsearch.js控制器中使用AngularJS查询,但是还没有能够在http请求中将它们作为params传递,或者在elasticsearch.js()方法中使用它们。推荐的语法是什么?
import elasticsearch from "elasticsearch";
export default class SearchDirectiveController {
constructor($scope, $http, SearchDirectiveService) {
this.es = new elasticsearch.Client({
host: 'http://192.168.99.100:9200',
log: 'trace'
});
this.search = () => {
this.es.search({
index: 'voter',
"query": {
"match": {
"first": "roger"
}
}
}
}).then((resp) => {
var hits = resp.hits.hits;
this.users = hits;
$scope.$digest();
},(err) => {
console.trace(err.message);
});
}
this.fullTextSearch = () => {
$http({
method: 'GET',
url: 'http://192.168.99.100:9200/voter/voter,address/_search'
}).then(function successCallback(resp) {
console.log(resp.data.hits.hits);
let hits = resp.data.hits.hits;
$scope.users = hits;
}, function errorCallback(err) {
console.trace(err.message);
}, {
params: {
"query": {
"match": {
"first": "roger"
}
}
}
});
}
}
}
SearchDirectiveController.$inject = ['$scope', '$http', 'SearchDirectiveService'];发布于 2015-11-17 16:44:44
我的问题是,我忘记了搜索对象上的键"body“:
this.searchQuery = (field) => {
return {
'query': {
'wildcard': {
'_all': '*' + this.all + '*'
}
}
};
};
this.search = (field) => {
this.es.search({
index: 'voter',
body: this.searchQuery(field)
}).then((resp) => {
const hits = resp.hits.hits;
this.users = hits;
$scope.$digest();
}, (err) => {
console.trace(err.message);
});
};
}https://stackoverflow.com/questions/33761006
复制相似问题