高峰只对攀登它而不是仰望它的人来说才有真正意义。

pinyin分词+ik分词搜索联想排序怎么使得搜索关键词 越靠前且占比越大的得分越高 排序越靠前

Elasticsearch | 作者 lower | 发布于2021年11月05日 | 阅读数:660

请教各位大佬pinyin分词+ik分词搜索联想排序怎么使得搜索关键词 越靠前且占比越大的得分越高 排序越靠前
 创建索引:
PUT /pinyin_ik_project
{
    "index": {
        "analysis": {
            "analyzer": {
                "ik_pinyin_analyzer": {  
                    "type": "custom",
                    "tokenizer": "ik_smart",
                    "filter": ["my_pinyin", "word_delimiter"]
                },
                "pinyin_analyzer": {
                    "type": "custom",
                    "tokenizer": "ik_max_word",
                    "filter": ["my_pinyin", "word_delimiter"]
                }
            },
            "filter": {
                "my_pinyin": {
                    "type" : "pinyin",
                    "keep_full_pinyin":false,
                    "keep_joined_full_pinyin" : true,
                    "keep_none_chinese_in_first_letter":false,
                    "keep_none_chinese_in_joined_full_pinyin":true,
                    "keep_original" : true, 
                    "limit_first_letter_length" : 16,
                    "lowercase" : true




}
 
创建映射数据结构

POST /pinyin_ik_project/project/_mapping
{
   
        "properties": {
          "id":{
            "type":"integer"
          },
            "userName": {
              "type": "text",
              "term_vector": "with_positions_offsets",
              "analyzer": "ik_pinyin_analyzer",  
              "boost": 10,
              "fielddata" : true,
              "fields": {
                     "keyword": {
             "type": "keyword",
          "ignore_above": 256
   }
                }
            },
            "reason":{
              "type": "text", 
              "term_vector": "with_positions_offsets",
              "analyzer": "ik_pinyin_analyzer",
              "boost": 10
            }
    
    }
}
查询:
GET /pinyin_ik_project/project/_search
{
  "from" : 4,
  "size" : 3,
  "timeout" : "60s",
  "query" : {
    "dis_max" : {
      "tie_breaker" : 0.0,
      "queries" : [
        {
          "bool" : {
            "must" : [
              {
                "term" : {
                  "projectType" : {
                    "value" : "1",
                    "boost" : 0.0
                  }
                }
              },
              {
                "dis_max" : {
                  "tie_breaker" : 0.0,
                  "queries" : [
                    {
                      "bool" : {
                        "should" : [
                            
                          {
                            "constant_score" : {
                              "filter" : {
                                "match_phrase_prefix" : {
                                  "name" : {
                                    "query" : "人人",
                                    "slop" : 0,
                                    "max_expansions" : 50,
                                    "boost" : 1.0
                                  }
                                }
                              },
                              "boost" : 1.0
                            }
                          }
                       
                        ],
                        
                        "disable_coord" : false,
                        "adjust_pure_negative" : true,
                        "boost" : 10
                      }
                    }
                  ],
                  "boost" : 1.0
                }
              }
            ],
            "disable_coord" : false,
            "adjust_pure_negative" : true,
            "boost" : 1.0
          }
        }
      ],
      "boost" : 1.0
    }
  }
}
查询返回结果
 {
            "_index": "pinyin_ik_project",
            "_type": "project",
            "_id": "7eba9ba67c503cbc98e399eb506d6c65",
            "_score": 10,
            "_source": {
            name:"人人易"
},
 {
            "_index": "pinyin_ik_project",
            "_type": "project",
            "_id": "7eba9ba67c503cbc98e399eb506d6c12",
            "_score": 10,
            "_source": {
            name:"冉冉健康"
},
{
            "_index": "pinyin_ik_project",
            "_type": "project",
            "_id": "7eba9ba67c503cbc98e399eb506d6c73",
            "_score": 10,
            "_source": {
            name:"人人网
},{
            "_index": "pinyin_ik_project",
            "_type": "project",
            "_id": "7eba9ba67c503cbc98e399eb506d6c24",
            "_score": 10,
            "_source": {
            name:"人工智能"
}
 

 
但是我想期望返回查询结果:
    人人易
   人人网
   人工智能
   冉冉健康
 
 
 
已邀请:

3xxx - github.com/3xxx

赞同来自:

用分值排名呀

要回复问题请先登录注册