ES基础入门
作者:互联网
1、ES倒排索引
数据库记录 DOCID代表主键
ES倒排索引 (二次查找)
a、对搜索的字段进行分词,关键词映射到对应数据库主键
b、ES对关键词进行分词,例如搜索”苹果手机“被分为”苹果“和”手机“
苹果匹配度>手机匹配度,ES根据匹配结果做排序,最终搜索结果展示
2、ES概念
INDEX: 相当于表
DOC: JSON对象
FIED: JSON对象的字段
MAPPING:DOC的JSON结构
3、测试
curl -X POST "localhost:9200/_analyze?pretty" -H 'Content-Type: application/json' -d '{ "analyzer": "ik_smart", "text": "中国人民共和国" }' #验证分词功能
创建INDEX
PUT http://192.168.110.128:9200/sku HTTP/1.1 User-Agent: Fiddler Host: 192.168.110.128:9200 Content-Type: application/json Content-Length: 441 { "mappings": { "properties": { "sku_id": { "type": "long" }, "title": { "type": "text", "analyzer": "ik_max_word", "search_analyzer": "ik_max_word" } } } } HTTP/1.1 200 OK content-type: application/json; charset=UTF-8 content-length: 62 {"acknowledged":true,"shards_acknowledged":true,"index":"sku"}
插入DOC
POST http://192.168.110.128:9200/sku/_doc/ HTTP/1.1 User-Agent: Fiddler Host: 192.168.110.128:9200 Content-Type: application/json Content-Length: 112 { "sku_id": 100002860826, "title": "烟台红富士苹果 5kg 一级铂金大果 单果230g以上 新鲜水果"} POST http://192.168.110.128:9200/sku/_doc/ HTTP/1.1 User-Agent: Fiddler Host: 192.168.110.128:9200 Content-Type: application/json Content-Length: 125 { "sku_id": 100000177760, "title": "苹果 Apple iPhone XS Max (A2104) 256GB 金色 移动联通电信4G手机 双卡双待"}
关键词查询
POST http://192.168.110.128:9200/sku/_search?pretty HTTP/1.1 User-Agent: Fiddler Host: 192.168.110.128:9200 Content-Type: application/json Content-Length: 54 { "query" : { "match" : { "title" : "苹果手机" }}}
HTTP/1.1 200 OK content-type: application/json; charset=UTF-8 content-length: 891 { "took" : 533, "timed_out" : false, "_shards" : { "total" : 1, "successful" : 1, "skipped" : 0, "failed" : 0 }, "hits" : { "total" : { "value" : 2, "relation" : "eq" }, "max_score" : 0.8594865, "hits" : [ { "_index" : "sku", "_type" : "_doc", "_id" : "uHyovYABUSVWsq2vBibk", "_score" : 0.8594865, "_source" : { "sku_id" : 100000177760, "title" : "苹果 Apple iPhone XS Max (A2104) 256GB 金色 移动联通电信4G手机 双卡双待" } }, { "_index" : "sku", "_type" : "_doc", "_id" : "t3ynvYABUSVWsq2v0yZU", "_score" : 0.18577608, "_source" : { "sku_id" : 100002860826, "title" : "烟台红富士苹果 5kg 一级铂金大果 单果230g以上 新鲜水果" } } ] } }
标签:sku,入门,基础,192.168,Content,json,110.128,ES,9200 来源: https://www.cnblogs.com/binfirechen/p/16266588.html