国产成人精品无码青草_亚洲国产美女精品久久久久∴_欧美人与鲁交大毛片免费_国产果冻豆传媒麻婆精东

18143453325 在線咨詢 在線咨詢
18143453325 在線咨詢
所在位置: 首頁 > 營銷資訊 > 電子商務(wù) > Elasticsearch構(gòu)建垂直搜索引擎實例

Elasticsearch構(gòu)建垂直搜索引擎實例

時間:2023-03-20 06:18:01 | 來源:電子商務(wù)

時間:2023-03-20 06:18:01 來源:電子商務(wù)

1 項目背景

最近了解了下Elasticsearch(簡稱Es),之前也了解過Es還通過構(gòu)建了日志分析系統(tǒng),在日志分析系統(tǒng)中基本沒有用到Es和搜索的基本知識點。在日志分析系統(tǒng)中直接通過應(yīng)用中構(gòu)建日志通過beats+logstash將日志導(dǎo)入到ES中,通過kibana工具對日志從各維度查詢和分析。ES在日志查詢分析方面有非常強悍的功能(以后在分析),在搜索引擎構(gòu)建上也有很突出的表現(xiàn)。

原來搜索方案該項目是自行用lunce封裝的一個類似于solr的搜索服務(wù),基本實現(xiàn)搜索空間配置化和索引建立和切換的方案,并沒有實現(xiàn)實現(xiàn)搜索語句自定義和配置。稍微復(fù)雜的搜索還需要定制特定的搜索類插件實現(xiàn)。

通過Elasticsearch來實現(xiàn)現(xiàn)有的搜索藥考慮的問題無非是業(yè)務(wù)上的可行性:

該項目是一個類似B2B的電商網(wǎng)站,但是本網(wǎng)站是一個會員制網(wǎng)站。說白了,付費用戶的商品廣告全部要排到前面,免費商戶的廣告排到后面。同時要求每個商戶在每次搜索召回的時候只出現(xiàn)一次召回。

之前自建的老的搜索服務(wù)是通過每天建立全量索引,建完全量索引的時候再做增量索來更新搜索數(shù)據(jù)。增量索引不存在什么問題,缺點就是建一次全量索引需要的時間太長,所需要的物理資源多。

2 ES實戰(zhàn)方案

在簡單了解了ES之后,感覺實現(xiàn)項目中的大部分搜索需求都是小菜一碟。唯一擔心會有問題的就是在搜索召回的時候?qū)γ總€廣告商家的所有的廣告物料分組拿出一個相關(guān)度最高的進行分組排序。之前舊的解決方案是搜索的時候拉出幾千個搜索結(jié)果,自行在內(nèi)存分組排序分頁。舊的自建搜索服務(wù)是自行手工設(shè)計的分布式系統(tǒng),一次行拉去也是并行同時在多個機器拉取在性能上還勉強過關(guān)。但是ES肯定不能用這樣的笨辦法處理分組排序的問題,還是試試通過ES聚合分組的方式來完成這樣的需求。具體過程代碼如下:

建立索引mappingPUT _index_template/index_search_product_template{ "version": 3, "priority": 200, "template": { "settings": { "index": { "number_of_shards": "5", "refresh_interval": "300s" } }, "mappings": { "properties": { "imgs": { "type": "keyword" }, "majorProdProp": { "type": "keyword" }, "keywords": { "analyzer": "whitespace", "type": "text" }, "productAttrValue": { "analyzer": "ik_smart", "type": "text" }, "productId": { "type": "long" }, "userSource": { "type": "keyword" }, "companyAddr": { "analyzer": "ik_smart", "type": "text" }, "source": { "type": "keyword" }, "categoryName": { "type": "keyword" }, "productName": { "analyzer": "ik_smart", "type": "text" }, "productAttr": { "analyzer": "ik_smart", "type": "text" }, "productZoneId": { "type": "long" }, "calCeil": { "type": "keyword" }, "minordernum": { "type": "integer" }, "compId": { "type": "long" }, "isPromote": { "type": "integer" }, "price": { "type": "long" }, "productStar": { "type": "integer" }, "shopId": { "type": "long" }, "categoryId": { "type": "keyword" }, "deliveryProvinceId": { "type": "integer" } } } }, "index_patterns": [ "index_product_*" ], "composed_of": [ "common_integer_id_template", "common_long_id_template" ]}構(gòu)造查詢DSL

GET index_product_payed/_search/{ "query": { "function_score": { "query": { "bool": { "should": [ { "term": { "productName": { "value": "燈泡", "boost": 300 } } } ] } }, "functions": [ { "field_value_factor": { "field": "productScore", "factor": 1, "modifier": "sqrt", "missing": 1 }} ], "boost_mode": "multiply" } }, "from": 0, "size": 0, "explain" : false, "profile": false, "aggs": { "group_by_userId": { "terms": { "field": "userId", "size": 400, "order": { "maxPrice": "desc" } } ,"aggregations": { "onlyOne": { "top_hits": { "size": 1, "sort": [ { "_score":{ "order": "desc" } } ], "explain" : false, "_source": { "includes": ["_id"","companyName","_score","price","isPromote","productScore"] } } }, "maxPrice":{ "max": { "script": { "source": "_score" } } } } } }}在這個DSL 中用到了聚合分組排序,用到了functions,field_value_factor中的排序影響的方式,但是這個只是一個簡化版,實際查詢比以上DSL稍微復(fù)雜一些。

時間衰減方面在另外一個搜索功能中運營,直接上代碼:

GET /index_wantbuy/_search{ "from":0, "size":100, "query":{ "script_score":{ "query":{ "bool":{ "should":[ { "multi_match":{ "query":"高價回收整廠設(shè)備 高價回收食品設(shè)備 高價回收面制品設(shè)備 高價回收肉制品設(shè)備", "fields":[ "productName^1.0", "remark^1.0", "tittle^1.0" ], "type":"best_fields", "operator":"OR", "slop":0, "prefix_length":0, "max_expansions":50, "zero_terms_query":"NONE", "auto_generate_synonyms_phrase_query":true, "fuzzy_transpositions":true, "boost":1 } } ], "adjust_pure_negative":true, "boost":1 } }, "script":{ "source":"if(doc['offerDeadline'].size()==0){ return 0; } return decayDateGauss(params.origin, params.scale, params.offset, params.decay, doc['offerDeadline'].value ) * _score ;", "lang":"painless", "params":{ "offset":"3d", "origin":"2022-01-12T15:14:35.525+0800", "scale":"30d", "decay":0.5 } }, "boost":1 } }, "_source":{ "includes":[ "tittle", "companyName", "buytype", "wantBuyId", "totalProd", "offerDeadline", "publicTime", "cityid", "userId", "provinceid", "areaid", "auditStatus", "unit" ], "excludes":[ ] }}這個查詢中沒有用上已經(jīng)被下個版本過期的function,而是直接使用script

GET /index_wantbuy/_search{ "from":0, "size":100, "query":{ "script_score":{ "query":{ "bool":{ "should":[ { "multi_match":{ "query":"高價回收整廠設(shè)備 高價回收食品設(shè)備 高價回收面制品設(shè)備 高價回收肉制品設(shè)備", "fields":[ "productName^1.0", "remark^1.0", "tittle^1.0" ], "type":"best_fields", "operator":"OR", "slop":0, "prefix_length":0, "max_expansions":50, "zero_terms_query":"NONE", "auto_generate_synonyms_phrase_query":true, "fuzzy_transpositions":true, "boost":1 } } ], "adjust_pure_negative":true, "boost":1 } }, "script":{ "source":"if(doc['offerDeadline'].size()==0){ return 0; } return decayDateGauss(params.origin, params.scale, params.offset, params.decay, doc['offerDeadline'].value ) * _score ;", "lang":"painless", "params":{ "offset":"3d", "origin":"2022-01-12T15:14:35.525+0800", "scale":"30d", "decay":0.5 } }, "boost":1 } }, "_source":{ "includes":[ "tittle", "companyName", "buytype", "wantBuyId", "totalProd", "offerDeadline", "publicTime", "cityid", "userId", "provinceid", "areaid", "auditStatus", "unit" ], "excludes":[ ] }}

關(guān)鍵詞:索引,實例,垂直

74
73
25
news

版權(quán)所有? 億企邦 1997-2025 保留一切法律許可權(quán)利。

為了最佳展示效果,本站不支持IE9及以下版本的瀏覽器,建議您使用谷歌Chrome瀏覽器。 點擊下載Chrome瀏覽器
關(guān)閉