西红柿, 番茄, 圣女
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" ] } } } } }