在弹性搜索中以单个查找查询获取链接文档

时间:2018-03-12 09:10:56

标签: python elasticsearch nosql

提供一些背景信息: 我想写一个批量更新查询(可能影响0.5 - 1M文档)。更新将在aspects字段(如下所示)中,大多数都是重复的。 我的想法是,如果我将其标准化为另一个实体(aspect_label),则更新的文档数量将大幅减少(例如最多500-1000)。

查询:我想知道是否有办法在弹性搜索中通过ID获取链接文档。

EG。如果我根据下面的映射在索引my_db中有文档。

要指出:processed_reviewsaspect_label

的孩子
{
   "my_db":{
      "mappings":{
         "processed_reviews":{
            "_all":{
               "enabled":false
            },
            "_parent":{
               "type":"aspect_label"
            },
            "_routing":{
               "required":true
            },
            "properties":{
               "data":{
                  "properties":{
                     "insights":{
                        "type":"nested",
                        "properties":{
                           "aspects":{
                              "type":"nested",
                              "properties":{
                                 "aspect_label_id":{
                                    "type":"keyword"
                                 },
                                 "aspect_term_frequency":{
                                    "type":"long"
                                 }
                              }
                           }
                        }
                     },
                     "preprocessed_text":{
                        "type":"text"
                     },
                     "preprocessed_title":{
                        "type":"text"
                     }
                  }
               }
            }
         }
      }
   }
}

另一个实体aspect_label

{
  "my_db": {
    "mappings": {
      "aspect_label": {
        "_all": {
          "enabled": false
        },
        "properties": {
          "aspect": {
            "type": "keyword"
          },
          "aspect_label_new": {
            "type": "keyword"
          },
          "aspect_label_old": {
            "type": "text"
          }
        }
      }
    }
  }
}

现在,我想在processed_reviews类型上编写一个搜索查询,以便将aspect_label_id实体替换为文档中aspect_label_new的值或aspect_label中的整个文档。 {1}}匹配ID。

{
    "_index":"my_db",
    "_type":"processed_reviews",
    "_id":"191b3bff-4915-4404-a05a-10e6bd2b19d4",
    "_score":1,
    "_routing":"5",
    "_parent":"5",
    "_source":{
        "data":{
            "preprocessed_text":"Good product I really like so comfortable and so light wait and looks good",
            "preprocessed_title":"Good choice",
            "insights":[
                {
                    "aspects":[
                        {
                            "aspect_label":"color",
                            "aspect_term_frequency":1
                        }
                    ]
                    }
            ]
        }
    }
}

此外,如果有更好的方法来解决这个问题/我的方法有问题,或者这是否可能。请告知我同样的事情。

0 个答案:

没有答案