Uninote
Uninote
用户根目录
每日点滴

<!DOCTYPE html> <html><head><meta http-equiv='Content-Type' content='text/html; charset=utf8'><title>mynote es elasticsearch</title> <script> var g_resRoot = '../../__res/'; var g_json_outline = '{"children":[{"children":[],"level":1,"lvNumber":"1","text":"note"},{"children":[],"level":1,"lvNumber":"2","text":"es commits"},{"children":[{"children":[],"level":2,"lvNumber":"3.1","text":"create mapping"}],"level":1,"lvNumber":"3","text":"索引管理"},{"children":[{"children":[],"level":2,"lvNumber":"4.1","text":"全文搜索 normal"},{"children":[],"level":2,"lvNumber":"4.2","text":"实际使用的查询"}],"level":1,"lvNumber":"4","text":"es 查询"}],"level":0,"lvNumber":"","text":"mynote es elasticsearch"}'; </script> <link rel='stylesheet' type='text/css' href='../../__res/common.css'><style>.s0{color:#000000;} .s1{color:#008000;} .s2{color:#000000;} .s3{color:#000000;} .s4{color:#0000ff;} .s5{color:#c80000;} </style> </head><body> <script src='../../__res/util.js'></script><div id='outline'> <li><a href='#ol_0' style='font-weight:bold; font-size:22px'>mynote es elasticsearch</a></li> <li> <a href='#ol_1' >note</a></li> <li> <a href='#ol_2' >es commits</a></li> <li> <a href='#ol_3' >索引管理</a></li> <li> <a href='#ol_4' >create mapping</a></li> <li> <a href='#ol_5' >es 查询</a></li> <li> <a href='#ol_6' >全文搜索 normal</a></li> <li> <a href='#ol_7' >实际使用的查询</a></li> </div>

<pre id='ol_0' class='title'>mynote es elasticsearch</pre> <pre><d class='s0'></d></pre> <pre><d class='s0'><a href='http://uninote.com.cn/book/1082456099#1434'>http://uninote.com.cn/book/1082456099#1434</a></d></pre> <pre><d class='s0'></d></pre> <pre><d class='s0'>params.php:</d></pre> <pre><d class='s1'>'es_host' </d><d class='s2'>=> </d><d class='s1'>'127.0.0.1'</d><d class='s2'>,</d></pre> <pre><d class='s1'>'es_port' </d><d class='s2'>=> </d><d class='s1'>'9200'</d><d class='s2'>,</d></pre> <pre><d class='s1'>'es_index' </d><d class='s2'>=> </d><d class='s1'>'mynote'</d><d class='s2'>,</d></pre> <pre><d class='s0'></d></pre> <pre><d class='s0'>\app\controllers\api\ArticleController::actionSearch</d></pre> <pre><d class='s3'>\app\controllers\SearchController::actionIndex</d></pre> <pre><d class='s3'> \app\models\api\Search::index</d></pre> <pre><d class='s3'></d></pre> <pre><d class='s0'>增删改查核心</d></pre> <pre><d class='s0'>E:\uninote\mynote\basic\models\ESBase.php</d></pre> <pre><d class='s0'></d></pre> <h1 id='ol_1'>note</h1> <pre><d class='s0'>搜索时,既要从数据库搜索tag等,又要从es搜索文章。</d></pre> <pre><d class='s0'></d></pre> <h1 id='ol_2'>es commits</h1> <pre><d class='s0'>SHA-1: 2e2145fd7b10e856b012b0a8a051bb7ec6df3a94</d></pre> <pre><d class='s0'>* search: 完成文章搜索</d></pre> <pre><d class='s0'></d></pre> <h1 id='ol_3'>索引管理</h1> <pre><d class='s3'>访问此链接,建立文章索引</d></pre> <pre><d class='s0'><a href='http://uninote.com.cn/api/synes'>http://uninote.com.cn/api/synes</a></d></pre> <pre><d class='s0'></d></pre> <pre><d class='s0'>删除index:</d></pre> <pre><d class='s0'>DELETE /mynote</d></pre> <pre><d class='s0'></d></pre> <pre><d class='s0'>清空es:</d></pre> <pre><d class='s0'>POST http://[域名]:9200/[es数据库名称]/article/_delete_by_query?refresh&slices=5&pretty 发送 </d></pre> <pre><d class='s0'></d></pre> <pre><d class='s0'>{</d></pre> <pre><d class='s0'> "query": {</d></pre> <pre><d class='s0'> "match_all": {}</d></pre> <pre><d class='s0'> }</d></pre> <pre><d class='s0'>}</d></pre> <pre><d class='s0'></d></pre> <h2 id='ol_4'>create mapping</h2> <pre><d class='s4'><a href='http://uninote.com.cn/book/1079089832#1116'>http://uninote.com.cn/book/1079089832#1116</a></d></pre> <pre><d class='s0'>PUT /mynote</d></pre> <pre><d class='s0'>{</d></pre> <pre><d class='s0'> "settings": {</d></pre> <pre><d class='s0'> "analysis": {</d></pre> <pre><d class='s0'> "analyzer": {</d></pre> <pre><d class='s0'> "ik_pinyin_analyzer": {</d></pre> <pre><d class='s0'> "type":"custom",</d></pre> <pre><d class='s0'> "tokenizer": "ik_smart",</d></pre> <pre><d class='s0'> "filter": ["my_pinyin","word_delimiter"]</d></pre> <pre><d class='s0'> }</d></pre> <pre><d class='s0'> },</d></pre> <pre><d class='s0'> "filter": {</d></pre> <pre><d class='s0'> "my_pinyin": {</d></pre> <pre><d class='s0'> "keep_joined_full_pinyin": "true",</d></pre> <pre><d class='s0'> "keep_none_chinese_in_first_letter": "false",</d></pre> <pre><d class='s0'> "lowercase": "true",</d></pre> <pre><d class='s0'> "keep_original": "false",</d></pre> <pre><d class='s0'> "keep_first_letter": "false",</d></pre> <pre><d class='s0'> "trim_whitespace": "true",</d></pre> <pre><d class='s0'> "type": "pinyin",</d></pre> <pre><d class='s0'> "keep_none_chinese": "false",</d></pre> <pre><d class='s0'> "limit_first_letter_length": "16",</d></pre> <pre><d class='s0'> "keep_full_pinyin": "false"</d></pre> <pre><d class='s0'> }</d></pre> <pre><d class='s0'> }</d></pre> <pre><d class='s0'> }</d></pre> <pre><d class='s0'> },</d></pre> <pre><d class='s0'> "mappings":{</d></pre> <pre><d class='s0'> "article":{</d></pre> <pre><d class='s0'> "properties":{</d></pre> <pre><d class='s0'> "abstract":{</d></pre> <pre><d class='s0'> "type":"text",</d></pre> <pre><d class='s0'> "analyzer":"ik_max_word"</d></pre> <pre><d class='s0'> },</d></pre> <pre><d class='s0'> "article_id":{</d></pre> <pre><d class='s0'> "type":"keyword"</d></pre> <pre><d class='s0'> },</d></pre> <pre><d class='s0'> "content":{</d></pre> <pre><d class='s0'> "type":"text",</d></pre> <pre><d class='s0'> "fields":{</d></pre> <pre><d class='s0'> "pinyin":{</d></pre> <pre><d class='s0'> "type":"text",</d></pre> <pre><d class='s0'> "analyzer":"ik_pinyin_analyzer"</d></pre> <pre><d class='s0'> }</d></pre> <pre><d class='s0'> },</d></pre> <pre><d class='s0'> "analyzer":"ik_max_word"</d></pre> <pre><d class='s0'> },</d></pre> <pre><d class='s0'> "id":{</d></pre> <pre><d class='s0'> "type":"long"</d></pre> <pre><d class='s0'> },</d></pre> <pre><d class='s0'> "recommend":{</d></pre> <pre><d class='s0'> "type":"byte"</d></pre> <pre><d class='s0'> },</d></pre> <pre><d class='s0'> "sort":{</d></pre> <pre><d class='s0'> "type":"long"</d></pre> <pre><d class='s0'> },</d></pre> <pre><d class='s0'> "status":{</d></pre> <pre><d class='s0'> "type":"byte"</d></pre> <pre><d class='s0'> },</d></pre> <pre><d class='s0'> "tag":{</d></pre> <pre><d class='s0'> "type":"keyword"</d></pre> <pre><d class='s0'> },</d></pre> <pre><d class='s0'> "thum":{</d></pre> <pre><d class='s0'> "type":"text"</d></pre> <pre><d class='s0'> },</d></pre> <pre><d class='s0'> "time":{</d></pre> <pre><d class='s0'> "type":"date"</d></pre> <pre><d class='s0'> },</d></pre> <pre><d class='s0'> "title":{</d></pre> <pre><d class='s0'> "type":"text",</d></pre> <pre><d class='s0'> "fields":{</d></pre> <pre><d class='s0'> "keyword":{</d></pre> <pre><d class='s0'> "type":"keyword"</d></pre> <pre><d class='s0'> },</d></pre> <pre><d class='s0'> "pinyin":{</d></pre> <pre><d class='s0'> "type":"text",</d></pre> <pre><d class='s0'> "analyzer":"ik_pinyin_analyzer"</d></pre> <pre><d class='s0'> }</d></pre> <pre><d class='s0'> },</d></pre> <pre><d class='s0'> "analyzer":"ik_max_word"</d></pre> <pre><d class='s0'> },</d></pre> <pre><d class='s0'> "updata_time":{</d></pre> <pre><d class='s0'> "type":"date"</d></pre> <pre><d class='s0'> },</d></pre> <pre><d class='s0'> "username":{</d></pre> <pre><d class='s0'> "type":"text",</d></pre> <pre><d class='s0'> "fields":{</d></pre> <pre><d class='s0'> "keyword":{</d></pre> <pre><d class='s0'> "type":"keyword"</d></pre> <pre><d class='s0'> },</d></pre> <pre><d class='s0'> "pinyin":{</d></pre> <pre><d class='s0'> "type":"text",</d></pre> <pre><d class='s0'> "analyzer":"ik_pinyin_analyzer"</d></pre> <pre><d class='s0'> }</d></pre> <pre><d class='s0'> },</d></pre> <pre><d class='s0'> "analyzer":"ik_max_word"</d></pre> <pre><d class='s0'> }</d></pre> <pre><d class='s0'> }</d></pre> <pre><d class='s0'> }</d></pre> <pre><d class='s3'> }</d></pre> <pre><d class='s3'>}</d></pre> <pre><d class='s0'></d></pre> <h1 id='ol_5'>es 查询</h1> <h2 id='ol_6'>全文搜索 normal</h2> <pre><d class='s0'>GET /mynote/article/_search</d></pre> <pre><d class='s0'>{</d></pre> <pre><d class='s0'> </d></pre> <pre><d class='s0'> "query": {</d></pre> <pre><d class='s0'> "match": {</d></pre> <pre><d class='s0'> "content": "创建完成"</d></pre> <pre><d class='s0'> }</d></pre> <pre><d class='s0'> }</d></pre> <pre><d class='s0'>}</d></pre> <pre><d class='s0'></d></pre> <h2 id='ol_7'>实际使用的查询</h2> <pre><d class='s0'>GET /mynote/article/_search</d></pre> <pre><d class='s0'>{</d></pre> <pre><d class='s0'> "query": {</d></pre> <pre><d class='s0'> "dis_max": {</d></pre> <pre><d class='s0'> "tie_breaker": 0.7,</d></pre> <pre><d class='s0'> "boost": 1.2,</d></pre> <pre><d class='s0'> "queries": [</d></pre> <pre><d class='s0'> {</d></pre> <pre><d class='s0'> "bool": {</d></pre> <pre><d class='s0'> "should": [</d></pre> <pre><d class='s0'> {</d></pre> <pre><d class='s0'> "multi_match": {</d></pre> <pre><d class='s0'> </d><d class='s5'>"query": "日志",</d></pre> <pre><d class='s0'> "fields": ["content", "content.pinyin", "username", "username.pinyin", "title","title.pinyin"],</d></pre> <pre><d class='s0'> "analyzer":"ik_max_word"</d></pre> <pre><d class='s0'> }</d></pre> <pre><d class='s0'> },</d></pre> <pre><d class='s0'> {</d></pre> <pre><d class='s0'> "term": {</d></pre> <pre><d class='s0'> "tag": {</d></pre> <pre><d class='s0'> </d><d class='s5'>"value": "123"</d></pre> <pre><d class='s0'> }</d></pre> <pre><d class='s0'> }</d></pre> <pre><d class='s0'> }</d></pre> <pre><d class='s0'> ]</d></pre> <pre><d class='s0'> }</d></pre> <pre><d class='s0'> }</d></pre> <pre><d class='s0'> ]</d></pre> <pre><d class='s0'> }</d></pre> <pre><d class='s0'> },</d></pre> <pre><d class='s0'> "highlight": {</d></pre> <pre><d class='s0'> "fields": [</d></pre> <pre><d class='s0'> {"tag" :{}},</d></pre> <pre><d class='s0'> {"title" :{}},</d></pre> <pre><d class='s0'> {"content" :{}},</d></pre> <pre><d class='s0'> {"username" :{}},</d></pre> <pre><d class='s0'> {"title.pinyin" :{}},</d></pre> <pre><d class='s0'> {"content.pinyin" :{}},</d></pre> <pre><d class='s0'> {"username.pinyin" :{}}</d></pre> <pre><d class='s0'> ]</d></pre> <pre><d class='s0'> },</d></pre> <pre><d class='s0'> "size": 10,</d></pre> <pre><d class='s0'> "from": 0,</d></pre> <pre><d class='s0'> "_source":[</d></pre> <pre><d class='s0'> "highlight", "title", "article_id", "title", "abstract", "thum", "id"</d></pre> <pre><d class='s0'> ]</d></pre> <pre><d class='s0'> }</d></pre> <pre><d class='s0'></d></pre> </body></html>

mynote_dev_log

mynote_init

点赞(0) 阅读(51) 举报
目录
标题