博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【商城】Elasticsearch搜索引擎-02.构建搜索系统客户端-实战
阅读量:4119 次
发布时间:2019-05-25

本文共 4030 字,大约阅读时间需要 13 分钟。

众所周知,Elasticsearch作为搜索引擎被广泛应用在各个领域, 索引作为Elasticsearch搜索实现核心之一,Elasticsearch底层使用倒排索引对分词进行文档映射,默认使用大数据常用的相似推荐算法(TF-IDF)进行打分,既实现文档高效检索,又完成文档评分排序。在上一篇基础上,本章将说明如何定义索引,并实现完整检索客户端。

1.索引定义

下面以实战商品搜索为例,说明复杂的商品索引定义,常用关键点如下:

  1. 分片和副本:定义索引分片数和副本数;
  2. 分词器:analyzer,如果搜索中文,可自定义索引字段的分词器;
  3. 标准化:normalizer,对字段标准化统一处理;
  4. 嵌套:Elasticsearch支持嵌套搜索,常用在商品优惠活动(子文档)与商品(主文档)一起搜索。
{  "aliases": {    "index_product": {}  },  "settings": {    "index": {      "number_of_shards": 5,      "number_of_replicas": 1    },    "analysis": {      "normalizer": {        "lowercase": {          "type": "custom",          "filter": [            "lowercase"          ]        }      }    }  },  "mappings": {    "index_product": {      "_all": {        "enabled": false      },      "dynamic_templates": [        {          "attribute_values": {            "match_mapping_type": "*",            "mapping": {              "type": "keyword"            }          }        }      ],      "properties": {        "id": {          "type": "long"        },        "spuId": {          "type": "long"        },        "categoryId": {          "type": "long"        },        "categoryIds": {          "type": "long"        },        "productCode": {          "type": "keyword"        },        "shopId": {          "type": "long"        },        "shopName": {          "type": "keyword"        },        "brandId": {          "type": "long"        },        "brandName": {          "type": "text",          "analyzer": "keyword"        },        "name": {          "type": "text",          "analyzer": "ik_max_word"        },        "nameKw": {          "type": "keyword",          "normalizer": "lowercase"        },        "mainImage": {          "type": "keyword",          "index": false        },        "status": {          "type": "integer"        },        "type": {          "type": "integer"        },        "businessType": {          "type": "integer"        },        "bitTag": {          "type": "long",          "index": false        },        "updatedAt": {          "type": "date",          "format": "yyyy-MM-dd HH:mm:ss||epoch_millis"        },        "lowPrice": {          "type": "long"        },        "highPrice": {          "type": "long"        },        "keyword": {          "type": "text",          "analyzer": "ik_max_word"        },        "saleQuantity": {          "type": "long"        },        "inStock": {          "type": "integer"        },        "shopCategoryIds": {          "type": "long"        },        "source": {          "type": "integer"        },        "channelList": {          "type": "long"        },        "integral": {          "type": "long"        },        "version": {          "type": "keyword"        },        "颜色": {          "type": "keyword"        },        "尺寸": {          "type": "keyword"        },        "长度": {          "type": "keyword"        },        "priceJson": {          "type": "keyword",          "index": false        },        "activityObject": {          "type": "nested",          "properties": {            "id": {              "type": "long"            },            "code": {              "type": "keyword"            },            "warmStartAt": {              "type": "long"            },            "startAt": {              "type": "long"            },            "expiredAt": {              "type": "long"            }          }        }      }    }  }}

2. 索引客户端

搜索客户端包括如下两部分核心内容;

  • 检索:查询转移,请求分发,请求结果处理,下载资源地址:;
  • 定义:索引、聚合、查询,详细的实现可以参考:,下载资源地址:;

搜索索引客户端

索引客户端

2.1 调用接口封装

/** * Copyright (c) 2020-2088 LEE POSSIBLE All Rights Reserved * Project:product-center * Package:com.leepossible.search.client * Version 1.0 * 搜索客户端接口定义 * @author 

2.2 聚合

/** * Copyright (c) 2020-2088 LEE POSSIBLE All Rights Reserved * Project:product-center * Package:com.leepossible.search.client.builder * Version 1.0 * Aggregate聚合Builder * @author 

2.3 排序

/** * Copyright (c) 2020-2088 LEE POSSIBLE All Rights Reserved * Project:product-center * Package:com.leepossible.search.client.builder * Version 1.0 * 排序builder模式 * @author 

转载地址:http://eccpi.baihongyu.com/

你可能感兴趣的文章
浅谈JavaScript的语言特性
查看>>
LeetCode第39题思悟——组合总和(combination-sum)
查看>>
LeetCode第43题思悟——字符串相乘(multiply-strings)
查看>>
LeetCode第44题思悟——通配符匹配(wildcard-matching)
查看>>
LeetCode第45题思悟——跳跃游戏(jump-game-ii)
查看>>
LeetCode第46题思悟——全排列(permutations)
查看>>
LeetCode第47题思悟—— 全排列 II(permutations-ii)
查看>>
LeetCode第48题思悟——旋转图像(rotate-image)
查看>>
驱动力3.0,动力全开~
查看>>
记CSDN访问量10万+
查看>>
Linux下Oracle数据库账户被锁:the account is locked问题的解决
查看>>
记CSDN访问20万+
查看>>
Windows 环境下Webstorm 2020.3 版本在右下角找不到Git分支切换部件的一种解决方法
查看>>
Electron-Vue项目中遇到fs.rm is not a function问题的解决过程
查看>>
飞机换乘次数最少问题的两种解决方案
查看>>
有向无回路图的理解
查看>>
设计模式中英文汇总分类
查看>>
WPF实现蜘蛛纸牌游戏
查看>>
单例模式
查看>>
工厂方法模式
查看>>