gpt4 book ai didi

angularjs - Elasticsearch查询解析失败

转载 作者:行者123 更新时间:2023-12-03 00:14:01 25 4
gpt4 key购买 nike

为什么此ES multi-match query返回400错误(错误请求)?

"query": {
"multi_match": {
"query": searchTerms,
"fields": ["content", "title"],
"operator": "and"
}
},
size: 100,
from: 0,
highlight: {
fields: {
"title": {number_of_fragments: 0},
"content": {number_of_fragments: 10,fragment_size: 300}
}
}
}

我将这个查询与AngularJS UI Bootstrap Typeahead代码一起使用
uib-typeahead="query as query._source.ymme for query in getSuggestions($viewValue)" typeahead-on-select="search($item)"

这是我的search()函数
    $scope.search = function() {
console.log($scope.searchTerms);
$scope.currentPage = 0;
$scope.results.documents = [];
$scope.isSearching = true;

return searchService.search($scope.searchTerms, $scope.currentPage).then(function(es_return) {
var totalItems = es_return.hits.total;
var totalTime = es_return.took;
var numPages = Math.ceil(es_return.hits.total / $scope.itemsPerPage);
$scope.results.pagination = [];

for (var i = 1; i <= 100; i++) {
if(totalItems > 0)
$scope.results.totalItems = totalItems;
$scope.results.queryTime = totalTime;

$scope.results.pagination = searchService.formatResults(es_return.hits.hits);
$scope.results.documents = $scope.results.pagination.slice($scope.currentPage, $scope.itemsPerPage);
}
}
),
function(error){
console.log('ERROR: ', error.message);
$scope.isSearching = false;
}
};

我不太确定出什么问题了吗?我在想它与$ scope有关,但是我不确定。当我将其用于ES的Sense插件时,该查询有效,并且如果我只是键入搜索词而不是从自动完成下拉列表中选择它,则该查询也有效。

如果是 $scope,我会缺少什么?

更新
所有分片均无法通过以下阶段:[query_fetch]
org.elasticsearch.search.SearchParseException:[hugetestindex] [0]:从[-1],size [-1]:解析失败[无法解析源[{“query”:{“multi_match”:{“query”: {“_index”:“hugetestindex”,“_ type”:“doc”,“_ id”:“57”,“_ score”:3.877801,“_ source”:{“ymme”:“本性至上”}},“字段” :[“content”,“title”],“operator”:“and”}},“size”:100,“from”:0,“highlight”:{“fields”:{“title”:{“number_of_fragments “:0},”内容“:{”片段数“:10,”片段大小“:300}}}}}]]]]]]

更新2 Object {_index: "hugetestindex", _type: "doc", _id: "56", _score: 2.5276248, _source: Object}
我认为这是问题所在,而不是搜索字词,而是其接收到的“对象” ....?

更新3 所以基本上是这样的,
[Object, Object, Object, Object, Object]
0: Object
_id: "229"
_index: "hugetestindex"
_score: 3.3071127
_source: Object
ymme: "bourne supremacy"
__proto__: Object
_type: "doc"
__proto__:
Object1:
Object2:
Object3:
Object4:
Object
length: 5
__proto__: Array[0]

其中“bourne supremacy”是_source对象中ymme字段的值,顶部带有5个对象的数组是es返回, es_return.hits.hits-这最后一个命中的数组。

最佳答案

解构对象的方式是通过执行以下操作:

object.data.hits.hits._source.field_name;

以上只是获得单个字段的值的一种表示法,您可能需要对每个值进行循环,因此可能类似于:
$scope.list = []
for hit in object.data.hits.hits {
$scope.list.push(hit._source.field);
}
console.log(list);

然后从您的HTML中使用ng-repeat或类似的方法来使用此列表,以获取列表中的每个术语。
<div ng-repeat="term in list">{{term}}</div>

如果您可以使用对象的外观以及从中获取什么数据来更新问题,那么我可以更新此答案以使其完全匹配。

更新
为了匹配您的数据结构,我假设您要从这些对象中提取每个ymme值。您需要执行以下操作:
<div ng-repeat="object in es_return.hits.hits">
{{object._source.ymme}}
</div>

只要确保“es_return”是一个$ scope变量,就可以像上面一样访问它或执行以下操作:
$scope.es_return = es_return;

在您的Angular代码中

关于angularjs - Elasticsearch查询解析失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38311353/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com