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为秒级响应。

整体性能可接受。

posted @ 2021-09-15 10:07  Arli  阅读(664)  评论(0编辑  收藏  举报