es设置分词最少一个字

es常用搜索的时候分词为1个字的时候会召回较多不太准确的内容,为增加召回准确性,设定分词去掉单个字的内容,需要自定义分词器,比如使用ik_max_word,可以自定义之后为其增加filter,设置为最少长度为2,即

"filter": {
  "len": {
      "type": "length",
      "min": 2
  }
}

然后在自定义的分词器进行引用

es默认使用tf/idf算法,简单理解就是当一个字段的内容越多,命中同样内容的时候,权重会减小,但是有时候不想被内容长度进行影响,比如标签,就根据命中的内容的多少来确定,这时候可以通过调整BM25参数变为0来让内容长度不再影响评分

"similarity": {
  "BM25_b_0": {
      "type": "BM25",
      "b": "0.0"
  }
}

然后在需要的字段进行引用,最后完整的示例如下

PUT test
{
     "settings": {
        "index": {
          "analysis": {
            "analyzer": {
              "custom_max_word": {
                  "type": "custom",
                  "tokenizer": "ik_max_word",
                  "filter": ["len"]
                }
            },
            "filter": {
              "len": {
                  "type": "length",
                  "min": 2
              }
            }
          },
          "similarity": {
              "BM25_b_0": {
                  "type": "BM25",
                  "b": "0.0"
              }
          }
        }
    },
    "mappings" : {
      "properties" : {
        "content" : {
          "type" : "text",
          "analyzer" : "custom_max_word"
        },
        "id" : {
          "type" : "long"
        },
        "tagNameList" : {
          "type" : "text",
          "analyzer" : "custom_max_word",
          "similarity": "BM25_b_0"
        },
        "title" : {
          "type" : "text",
          "analyzer" : "custom_max_word"
        }
      }
    
  }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值