ElasticSearch Join Field Type性能测试

一.场景描述

使用ElasticSearch做用户画像+人群画像时,面临的比较难以解决的问题是用户画像和详情记录间的关联,虽然ES支持任意维度的标签,但在大量维度的标签存储和查询时时一般仅能支持到标签维度而非数值。

如下面的方案,会存在无法独立使用ES计算用户画像和详单数据关联的问题:

https://blog.csdn.net/weixin_44318830/article/details/114006105

https://max.book118.com/html/2021/0110/6055110241003045.shtm


image

下面是ES提供的一种JOIN方案,接下来的测试主要是为了验证是否能够解决问题:

https://www.elastic.co/guide/en/elasticsearch/reference/current/parent-join.html#_parent_join_queries_and_aggregations


PUT test_record_join
{
   "settings":{
        "index.mapping.total_fields.limit":1000000,
        "number_of_shards":9,
        "number_of_replicas":1,
        "refresh_interval": "120s",
        "index.translog.flush_threshold_size": "1g"
    },
  "mappings": {
    "dynamic": "true",
    "numeric_detection":false,
    "dynamic_date_formats": ["yyyy-MM-dd'T'HH:mm:ssZ"],
    "dynamic_templates": [
      {
        "strings_as_keyword": {
          "match_mapping_type": "string",
          "mapping": {
            "type": "keyword"
          }
        }
      }
    ],
    "properties": {
      "joinRecordType":{
       "type":"join",
       "relations":{
        "user":"product_time_daily"
       }
      }
    }
  }
}

以上是创建一个用户->产品每日使用时长的父子关系,属于one-to-many的数据模型,即一个user对应多个产品每日使用时长。

场景1:搜索使用了某产品的所有用户。

GET test_record_join/_search
{
  "query": {
    "term": {
      "productName":"A产品"
      
    }
  }
}

场景2:统计使用了某产品的用户使用的所有产品的情况

GET test_record_join/_search
{
  "query": {
    "has_parent": {
      "parent_type": "user",
      "query": {
        "has_child": {
       "type": "product_time_daily",
       "query": {
        "term": {
      "productName":"B产品"
       
    }
      }
    }
      }
    }
  },
  "aggs": {
    "children": {
      "terms": {
        "field": "productName", 
        "size": 10000
      }
    }
  }
  
}



场景1为毫秒级响应。

场景2为秒级响应。

整体性能可接受。

如果,您认为阅读这篇博客让您有些收获,不妨点击一下右下角的【推荐】。
如果,您希望更容易地发现我的新博客,不妨点击一下左下角的【关注我】。
如果,您对我的博客所讲述的内容有兴趣,请继续关注我的后续博客,我是【Arli】。

本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

原文地址:https://www.cnblogs.com/arli/p/15271004.html