falldog 发表于 2019-1-29 09:31:27

elasticsearch 同义词配置

  在config目录下面,存放synonyms.txt
  curl -XPOST 'http://localhost:9200/sy' -d '{
  "analysis": {
  "analyzer":{
  "mysynonym":{
      "type": "custom",
  "tokenizer":"ik_max_word",
  "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://127.0.0.1:9200/sy/sy/_search?pretty' -d '{
  "from" : 0,
  "size" : 2,
  "query": {
  "bool" : {
  "must" : {
  "query_string" : {
  "query" : "圣女果"
  }
  }
  }
  }
  }'



页: [1]
查看完整版本: elasticsearch 同义词配置