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":"杯子"}}]}}}

elasticsearch 同义词权重搜索

 


 


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



elasticsearch 同义词权重搜索

 

 

 

上一篇:FutureWarning: Passing (type, 1) or ‘1type‘ as a synonym of type is deprecated; in a future version


下一篇:P3146 [USACO16OPEN]248 dp