如何从highlightfield中获取elasticsearch中的外部对象

时间:2016-02-29 16:38:52

标签: elasticsearch

我有一些这样的文件:

{
"content": "DocumentFile",
"title": "no title",
"post_id": "18",
"url": "http://localhost/wp/?p=18",
"attachments": [{
    "content": "Hi this is extrach data of file",
    "hash": "UPR9BC57IW3PUNTQ3LP79Q6UN0V3ZR7AAFJNUFGH",
    "name": "file."
}],
"isDeleted": "false",
"__creationdDate": "1456758952671"}

我初始化弹性搜索映射,所以:

{
"post": {
    "properties": {
        "content": {
            "type": "string",
        },
        "title": {
            "type": "string",
        },
        "url": {
            "type": "string",
        },
        "post_id": {
            "type": "string",
            "fields": {
                "raw": {
                    "type": "integer",
                    "index": "not_analyzed"
                }
            }
        },
        "attachments": {
            "type": "nested",
            "include_in_parent": true,
            "properties": {
                "hash": {
                    "type": "string",
                    "analyzer": "vira_analyzer"
                },
                "name": {
                    "type": "string",
                    "analyzer": "vira_analyzer"
                },
                "content": {
                    "type": "string",
                    "analyzer": "vira_analyzer"
                }
            }
        },
        "_uid": {
            "type": "string",
            "analyzer": "vira_analyzer"
        }
    }
}}

我将title,content,attachments.name,attachments.content添加到highlightfields

我在本文档中搜索数据 它在attachments.content和elasticsearch中找到它 现在我想得到这个附件的哈希码,我该怎么办? 有没有弹性搜索给我块的名称或内容搜索查询? 通过这个:

  

Text [] highlightFragments = hitHighLights.get(field).getFragments();

弹性搜索我只是该附件的内容字段。我想要所有这些块,有点像这样:

{
    "content": "Hi this is extrach data of file",
    "hash": "UPR9BC57IW3PUNTQ3LP79Q6UN0V3ZR7AAFJNUFGH",
    "name": "file."
}

(一种方法是获取该文档的来源并在其中搜索,但这并不好,因为速度会下降很多。)

0 个答案:

没有答案