要不要再翻翻文档呢?

输入词匹配句子得分问题

Elasticsearch | 作者 sophie | 发布于2019年09月12日 | 阅读数:951

有两个语句
1.这是京东白板
2.京东白板笔

输入白板,如何做到让第一句匹配度更高
已邀请:

liuxg - Elastic

赞同来自:

刚才试了一下,安装文档里的方法:https://blog.csdn.net/UbuntuTo ... 16428
 
PUT /chinese/_doc/10
{
  "content": "这是京东白板"
}

PUT /chinese/_doc/11
{
  "content": "京东白板笔"
}

GET /chinese/_search 
{
  "query": {
    "match": {
      "content": "白板"
    }
  }
}
 
第一个是排在前面的:
 
{
  "took" : 0,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 2,
      "relation" : "eq"
    },
    "max_score" : 0.75491273,
    "hits" : [
      {
        "_index" : "chinese",
        "_type" : "_doc",
        "_id" : "10",
        "_score" : 0.75491273,
        "_source" : {
          "content" : "这是京东白板"
        }
      },
      {
        "_index" : "chinese",
        "_type" : "_doc",
        "_id" : "11",
        "_score" : 0.6747451,
        "_source" : {
          "content" : "京东白板笔"
        }
      }
    ]
  }
}
 
我也试了如下的方法:
GET /chinese/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "prefix": {
            "content": {
              "value": "白板",
              "boost": 2
            }
          }
        }
      ], 
      "should": [
        {
          "match": {
            "content": "白板"
          }
        }
      ]
    }
  }
}
显示的结果如下:
 
{
  "took" : 0,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 2,
      "relation" : "eq"
    },
    "max_score" : 2.7549129,
    "hits" : [
      {
        "_index" : "chinese",
        "_type" : "_doc",
        "_id" : "10",
        "_score" : 2.7549129,
        "_source" : {
          "content" : "这是京东白板"
        }
      },
      {
        "_index" : "chinese",
        "_type" : "_doc",
        "_id" : "11",
        "_score" : 2.674745,
        "_source" : {
          "content" : "京东白板笔"
        }
      }
    ]
  }
}
 

要回复问题请先登录注册