zoukankan      html  css  js  c++  java
  • 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":"保温杯"}}]}}}



  • 相关阅读:
    9.5---所有字符串的排列组合(CC150)
    9.4---集合子集(CC150)
    9.3---魔术索引(CC150)
    5.3(2)----机器人走方格2(CC150)
    9.2---机器人走方格(CC150)
    9.1---上楼梯(CC150)
    5.3---找最近的两个数(CC150)
    5.8---像素设定(CC150)
    7.4---加法替代运算(CC150)
    4.9---二叉树路径和(CC150)
  • 原文地址:https://www.cnblogs.com/wangchuanfu/p/14166879.html
Copyright © 2011-2022 走看看