在elasticsearch-2.3.1/config目录下面,存放synonyms.txt
curl -XPOST ‘http://localhost:9200/sy‘ -d ‘{
"analysis": {
"analyzer":{
"mysynonym":{
"type": "custom",
"tokenizer":"ik_smart",
"filter":[
"local_synonym"
]
}
},
"filter":{
"local_synonym":{
"expand":true,
"ignore_case":true,
"type":"synonym",
"synonyms_path":"synonym.txt"
}
}
}
}‘
curl -XPOST ‘http://localhost:9200/sy/sy/_mapping‘ -d ‘{
"sy":{
"_all":{
"search_analyzer":"ik_smart",
"analyzer":"mysynonym"
},
"properties":{
"name":{
"type":"string"
},
"title":{
"type":"string"
},
"number":{
"type": "long"
}
}
}
}
}‘
curl -XPOST http://127.0.0.1:9200/sy/sy/1?pretty -d‘
{"name":"番茄" , "title" : "FQtitle" , "number" : 10000}
‘
curl -XPOST http://127.0.0.1:9200/sy/sy/2?pretty -d‘
{"name":"西红柿" , "title" : "XHStitle" , "number" : 20000}
‘
curl -XPOST http://127.0.0.1:9200/sy/sy/3?pretty -d‘
{"name":"圣女果" , "title" : "SVGtitle" , "number" : 30000}
‘
curl -XGET ‘http://10.2.19.172:9200/sy/sy/_search?pretty‘ -d ‘{
"from" : 0,
"size" : 2,
"query": {
"bool" : {
"must" : {
"query_string" : {
"query" : "圣女果"
}
}
}
}
}‘