在文档中搜索并获取与我在 elasticsearch 中的搜索匹配的属性

search in a document and just get the properties that match my search in elasticsearch

in my index of elasticsearch, I have a type with multiple properties. and each one have different values..

now my question is:

in my search query i want to get just the result that are matched to mine.. not hole document! i want elastic get me just result that are matched! not all document with matched and not-matched result, that returned to me because of matched ones

感谢朋友们的帮助..


这里有一个关于我的问题的例子: 例如,在我的文档中,我有一个名为 属性 的文件夹,它有一些 属性,可以有多个值..

"folder":  [
       [
      "employer_folder_id" => 142
      "status_id" => 140
      "folder" =>  [
        "id" => 142
        "employer_id" => 11
      ]
      "created_at" => "2017-04-12"
      "is_applied" => 1
      "hire_stage_id" => 144
    ]
     [
      "employer_folder_id" => 7922
      "status_id" => 141
      "folder" =>  [
        "id" => 7922
        "employer_id" => 11
      ]
      "created_at" => "2017-04-12"
      "is_applied" => 1
      "hire_stage_id" => 144
    ]
]

这里我想搜索 status_id = 141,

的文件夹

但是当我搜索它时 return 是我的漏洞文档.. 与其他状态 ID... 但我只想 return 我 status_id=141,并且也适用于其他领域

文件夹在我的类型中是 属性..

您可以使用 fields 查询只得到那些您需要的字段作为结果,例如;

{
    'query': {
        'bool': {
            'must': [
                {
                    'term': {
                        'Key1': 'value1'
                    }
                }
            ]
        }
    },
    'fields': [
        'Key1',
        'Key2',
        'Key3'
    ]
}

这将 return 所有具有 key1 且值为 value1 的文档。每个文档将只有 3 个字段,'Key1','Key2','Key3'

最好提供您的映射和查询。
我认为那是因为你的数组类型是 object 类型。在这种情况下,当每个字段都是值数组时,elastic 会将您的 folder 属性 展平为文档。像这样:
在索引时完成

folder.status_id: [140, 144, 141, 144]  

这就是为什么您的查询会 return 漏洞文档。
您应该尝试使用 nested 对象类型。
Useful Link