我正在使用:
AngularJs:AngularJS v1.2.22
Bootstrap:Bootstrap v3.1.1 + ui-bootstrap-tpls-0.11.0.js
Elasticsearch.angular:elasticsearch - v2.4.0 - 2014-07-30
我使用angular进行前端工作,我想在elasticsearch文档上使用twitter-bootstap typeahead进行自动完成输入。 我可以使用angularJs查询elasticsearch并正确获取数据(通过将它们放在范围内)但是当我尝试 asynchrone查询时失败并出现错误**“错误:匹配未定义”(完整错误)她:http://pastebin.com/CJSubYbp)
在angularjs中,为elasticsearch提供服务:
interfaceApp.service('elasticQuery', function (esFactory) {
return esFactory({ host: 'localhost:9200' });
});
我的控制器: 'use strict';
/* Controllers */
var searchSimpleModules = angular.module('searchSimpleModules', ['ngRoute']);
searchSimpleModules.controller('searchSimpleCtrl', function ($scope, $rootScope, $routeParams, $location, elasticQuery) {
$scope.simplequery = "";
$scope.autocomplete = function(value) {
$scope.simplequery = value;
var index_p = 'donnees';
var size_p = 50;
var body_p = {
"query": {
"query_string": { "query" : value +"*" }
}
};
elasticQuery.search({
index: index_p,
size: size_p,
body: body_p
}).then(function (response) {
$scope.hits= response.hits.hits;
});
};
$scope.find = function () {
elasticQuery.search({
index: 'donnees',
size: 50,
body: { "query": { "query_string": { "query" : "P000023*" } } }
}).then(function (response) {
$scope.hits= response.hits.hits;
});
};
});
html输入:
<input required type="text"
popover="Rechercher un terme sur toute la partie {{simplesearch.domaine}}.Il est possible d'utiliser des *,? et double quote."
popover-trigger="focus"
placeholder="recherche globale"
class="form-control"
typeahead="entree for entree in autocomplete($viewValue)"
ng-model="simplequery"
>
在firebug控制台中,我看到我在服务“http.get()”之前收到错误。
我做了很多搜索来调试这个,但我无法摆脱它。
欢迎任何建议。谢谢 最好的问候
答案 0 :(得分:0)
更新1:我找到了另一个解决方案,但没有使用elastic.js
<input required type="text"
popover="Rechercher un terme sur toute la partie {{simplesearch.domaine}}.Il est possible d'utiliser des *,? et double quote."
popover-trigger="focus"
placeholder="recherche globale"
class="form-control search-query"
ng-model="simplequery"
typeahead="entree as entree.data for entree in autocomplete($viewValue) | filter:$viewValue | limitTo:15 "
typeahead-on-select="onSelect($model)"
/>
JS:
$scope.simplequery = {id:"",data:""};
$scope.autocomplete = function(val) {
var body = '{"fields" : [ "O_OCCURRENCEID","C_COLLECTIONID", "C_COLLECTIONCODE", "I_INSTITUTIONID", "I_INSTITUTIONCODE" ], "query" : {"query_string" : { "query" : "*'+val+'*" }},"highlight":{"pre_tags" : ["<strong>"],"post_tags" : ["</strong>"],"fields":{"*": {}}}}';
return $http.get($rootScope.elastic_host + 'specimens/_search?', {
params: { // q: val
source : body
}
}).then(function(res){
var keywords = [];
for (var i in res.data.hits.hits) {
var highlights = (res.data.hits.hits[i]).highlight;
var ligneTmp ="";
for(var j in highlights){
ligneTmp += highlights[j][0] + " ";
}
keywords[i]= {id:"id"+i,data:ligneTmp};
}
return keywords;
});
};
$scope.onSelect = function (selection) {
$scope.simplequery.data = selection.data;
$scope.simplequery.id = selection.id;
...
};
答案 1 :(得分:0)
更新2:使用elasticsearch-angular.js:
autocomplete/typeahead angularjs bootstrap on elasticsearch
(由于返回&#34;返回弹性查询({...})&#34;缺失,因此无法正常工作)