西紅柿, 番茄, 聖女
es設置索引和自定義解析器php
PUT /megacorp { "mappings": { "employee": { "properties": { "name":{ "type": "text", "analyzer": "ik-index", //指定索引時候用的解析器 "search_analyzer": "ik-smart" //指定搜索時候用的解析器 } } } } , "settings": { "analysis": { "filter": { "local_synonym" : { "type" : "dynamic_synonym", "synonyms_path" : "analysis/synonym.txt" } }, "analyzer": { "ik-index": { "type": "custom", "tokenizer": "ik_max_word", "filter": [ "local_synonym" //對同義詞進行了過濾 ] }, "ik-smart": { "type": "custom", "tokenizer": "ik_smart", "filter": [ "local_synonym" ] } } } } }
GET /megacorp/_analyze { "analyzer": "ik-index", "text": "西紅柿" }
{ "tokens": [ { "token": "西紅柿", "start_offset": 0, "end_offset": 3, "type": "CN_WORD", "position": 0 }, { "token": "番茄", "start_offset": 0, "end_offset": 3, "type": "SYNONYM", "position": 0 }, { "token": "聖女", "start_offset": 0, "end_offset": 3, "type": "SYNONYM", "position": 0 } ] }
PUT /megacorp/employee/1 { "name" : "聖女果" } PUT /megacorp/employee/2 { "name" : "番茄" }
GET /megacorp/employee/_search { "query":{ "match": { "name": "西紅柿" } } }
http://localhost/synonym/list
$response->setLastModified($lastModified); $response->setEtag($etag, true); $response->headers->set('Content-Type', 'text/plain');
W/"db8b38e8a3257a2f195b727eceb2c5d3"
PUT /megacorp { "mappings": { "employee": { "properties": { "name":{ "type": "text", "analyzer": "ik-index", //指定索引時候用的解析器 "search_analyzer": "ik-smart" //指定搜索時候用的解析器 } } } } , "settings": { "analysis": { "filter": { "remote_synonym": { "type" : "dynamic_synonym", "synonyms_path" : "http://localhost/synonym/list", "interval": 60 // 沒60s調取一次接口 }, "local_synonym" : { "type" : "dynamic_synonym", "synonyms_path" : "analysis/synonym.txt" } }, "analyzer": { "ik-index": { "type": "custom", "tokenizer": "ik_max_word", "filter": [ "remote_synonym", //對遠程同義詞進行了過濾 "local_synonym" //對本地同義詞進行了過濾 ] }, "ik-smart": { "type": "custom", "tokenizer": "ik_smart", "filter": [ "local_synonym" ] } } } } }