其他分享
首页 > 其他分享> > elasticsearch 同义词权重搜索

elasticsearch 同义词权重搜索

作者:互联网

问题描述:

    在配置同义词搜索的时候,如何区分权重.比如,同义词文件中配置"杯子,保温杯",用户在搜索杯子的时候,想让关于杯子的数据展示在前面,或者输入保温杯的时候,想让保温杯的数据展示在前面?

PUT /synonym_test/
{
  "settings": {
    "analysis": {
      "analyzer": {
        "no_synonyms": {
          "type": "custom",
          "tokenizer": "ik_smart"
        },
        "synonyms": {
         "type": "custom",
          "tokenizer": "ik_smart",
          "filter": [
            "synonym"
          ]
        }
      },
      "filter": {
        "synonym": {
          "type": "synonym",
          "synonyms_path": "analysis/synonym.txt"
        }
      }
    }
  },
  "mappings": {
    "properties": {
      "syn": {
        "type": "text",
        "analyzer": "synonyms"
      },
      "no_syn": {
        "type": "text",
        "analyzer": "no_synonyms"
      }
    }
  }
}






POST synonym_test/_doc/1
{
  "syn": "江苏潮流杯子价格实惠",
  "no_syn": "江苏潮流杯子价格实惠"
}
POST synonym_test/_doc/2
{
  "syn": "乌鲁木齐潮流杯子样式绝美",
  "no_syn": "乌鲁木齐潮流杯子样式绝美"
}
POST synonym_test/_doc/3
{
  
  "syn": "Momscook 潮流 保温杯",
  "no_syn": "Momscook 潮流 保温杯"
}

POST synonym_test/_doc/4
{

   "syn": "上海潮流保温杯好用",
  "no_syn": "上海潮流保温杯好用"
}


GET /synonym_test/_search
{"query":{"bool":{"should":[{"match":{"syn":{"query":"杯子","boost":10}}},{"match":{"no_syn":"杯子"}}]}}}

 


 


GET /synonym_test/_search
{"query":{"bool":{"should":[{"match":{"syn":{"query":"保温杯","boost":10}}},{"match":{"no_syn":"保温杯"}}]}}}



 

 

 

标签:synonym,no,同义词,syn,搜索,保温杯,test,elasticsearch,杯子
来源: https://www.cnblogs.com/wangchuanfu/p/14166879.html