【问题标题】:how to search in document in elasticsearch如何在elasticsearch中搜索文档
【发布时间】:2017-10-21 01:12:01
【问题描述】:

我想使用 elasticsearch 搜索 my_type 的属性..

例如,在 my_type 中,我有一个名为“folder_applications”的属性:

"folder_applications":  [
   *[
    "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" => 143
  ]
]

* -> first array
** -> second array

例如,我想在 my_type 中搜索 status_id => 141 的对象;

当我搜索这个时,我的搜索结果返回包含所有状态的孔文档.. 但我只想要 status_id => 141...而不是 140 或任何其他..例如我想获取 folder.id => 7922 && status_id => 141.. 搜索结果只显示我示例的第二个数组。

其他搜索也会发生这种情况。我该如何处理?

【问题讨论】:

    标签: search elasticsearch types document


    【解决方案1】:

    如果您的folder_applications 属性是nested,您可以使用Inner Hits 仅获取folder_applications 数组中的对象。
    更新:示例:

    {
    "query":{
      "nested":{
         "path":"folder_applications",
         "query":{
            "bool":{
               "must":[{"match":{
                        "folder_applications.status_id":141
                     }
                  },
                  {"nested":{
                        "path":"folder_applications.folder",
                        "query":{
                           "match":{
                              "folder_applications.folder.id":7922
                           }
                        }
                     }
                  }
               ]
            }
         },
         "inner_hits":{}
      }
     }
    }
    

    【讨论】:

    • 谢谢@TarasKohut,你能给我举个例子吗?是的folder_applications 有嵌套类型......但我不知道如何编写我的查询......因为我也有布尔查询......我想将这些组合在一起......
    猜你喜欢
    • 1970-01-01
    • 2021-05-20
    • 1970-01-01
    • 2021-07-17
    • 2015-05-23
    • 1970-01-01
    • 2012-10-22
    • 2014-06-25
    • 1970-01-01
    相关资源
    最近更新 更多