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



  • 相关阅读:
    jQuery 获取jsp页面中用iframe引入的jsp页面中的值
    spring事务管理
    mysql中将多行数据合并成一行数据
    C语言字符串格式化输出
    gdb无法单步调试
    Linux系统glibc库版本信息查看
    gcc编译命令行依赖库的指定顺序
    HDFS的基础与操作
    搭建Kubernetes容器集群管理系统
    如何在 CentOS 里下载 RPM 包及其所有依赖包
  • 原文地址:https://www.cnblogs.com/wangchuanfu/p/14166879.html
Copyright © 2011-2022 走看看