我想在elasticsearch db上的嵌套文档中搜索字段。我使用以下命令搜索嵌套对象上的字段(获得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"
}
]
}
}
}
]
}
}
答案 0 :(得分:0)
最后,为了跳过这个问题,我使用了角度和弹性之间的中间件服务器。这个服务器是一个python服务器,很容易通过curl在elasticsearch上进行GET / POST。
此外,我尝试直接从Angular(html GET)使用curl,但由于惯例,html服务器可以忽略GET请求中的数据。因此,通过来自Angular的卷曲,不可能对弹性进行请愿。