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為秒級響應。

整體性能可接受。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM