gpt4 book ai didi

javascript - 如何使用 elasticsearch.js 和 Angular 在 Elasticsearch 上搜索嵌套对象

转载 作者:行者123 更新时间:2023-11-28 05:49:39 26 4
gpt4 key购买 nike

我想搜索我的elasticsearch 数据库上嵌套文档的字段。我使用以下命令来搜索嵌套对象上的字段(获得 10 个内部命中):

curl -X GET 'http://localhost:9200/jira-dev/_search?pretty=true' -d '
{
"_source" : false,
"query" : {
"nested" : {
"path" : "issues",
"query" : {
"bool": {
"should": [
{
"wildcard":{
"issues.fields.description":"*migrate*"
}
},
{
"wildcard":{
"issues.fields.comment.comments.body":"*autodeploy*"
}
}
]
}
},
"inner_hits" : {"size": 5000}
}
}
}'

但是当我尝试以这种方式使用elasticsearch.js调用它时,它没有得到任何结果:

client.search({
index: 'jira-dev/',
type: 'jira',
body: {
query: {
nested : {
path : "issues",
query : {
bool: {
should: [
{
wildcard:{
"issues.fields.description":"*migrate*"
}
},
{
wildcard:{
"issues.fields.comment.comments.body":"*autodeploy*"
}
}
]
}
},
inner_hits : {size: 5000}
}
}
}
}).then(function (resp) {
var hits = resp.hits.totals;
console.log('works');
}, function (err) {
console.log('epic fail');
console.trace(err.message);
});

我认为我使用的语法不正确,但我没有找到任何使用elasticsearch.js 的嵌套查询的示例。

提前致谢。

编辑:

根据要求,以下是文档的配置:

curl -X POST 'http://localhost:9200/jira-dev/' -d '{
"mappings" : {
"jira" : {
"properties" : {
"expand" : {"type" : "string"},
"startAt" : {"type" : "integer"},
"maxResults" : {"type" : "integer"},
"total" : {"type" : "integer"},
"issues" : {
"type" : "nested",
"include_in_parent" : false,
"properties" : {
"created" : {"type" : "date", "format" : "date_hour_minute_second_fraction"}
}
}
}
}
},
"settings" : {
"number_of_shards" : 5,
"number_of_replicas" : 1
}
}'

和一个例子:

{

"_index": "jira-dev",
"_type": "jira",
"_id": "1",
"_version": 1,
"_score": 1,
"_source": {
"expand": "schema,names",
"startAt": 0,
"maxResults": 1000,
"total": 604,
"issues": [
{

"key": "STACK-1",
"fields": {
"summary": "A nice summary",
"created": "2016-06-28T09:45:32.000+0000",
"description": null,
"comment": {
"startAt": 0,
"maxResults": 1,
"total": 1,
"comments": [
{
"self": url",
"id": "30293",
"author": {
"name": "stack_overflow",
"key": "stack_overflow"
},
"body": "Following epic has been created: url",
"updateAuthor": {
"name": "stack_overflow",
"key": "stack_overflow",
"timeZone": "Europe/Madrid"
},
"created": "2016-03-04T10:09:11.000+0000",
"updated": "2016-03-04T10:09:11.000+0000"
}
]
}
}
}
]
}
}

最佳答案

最后,为了跳过这个问题,我使用了 Angular 和 Elastic 之间的中间件服务器。该服务器是一个Python服务器,可以通过curl轻松地在elasticsearch上执行GET/POST。

此外,我尝试直接从 Angular (html GET) 使用curl,但由于约定,html 服务器可以忽略 GET 请愿上的数据。因此,通过 Angular 的curl 不可能在弹性上进行请求。

关于javascript - 如何使用 elasticsearch.js 和 Angular 在 Elasticsearch 上搜索嵌套对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38182383/

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