1

我想在我的 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"
                            }
                        ]
                    }
                }
            }
        ]
    }
}
4

1 回答 1

0

最后,为了跳过这个问题,我使用了 angular 和 elastic 之间的中间件服务器。该服务器是一个 python 服务器,很容易通过 curl 在 elasticsearch 上执行 GET/POST。

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

于 2016-07-29T09:15:55.093 回答