Elasticsearch:没有任期时会积极推动 [英] Elasticsearch: positive boost when term is not present

查看:39
本文介绍了Elasticsearch:没有任期时会积极推动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Elasticsearch对产品进行简单的搜索.

I'm trying to implement a simple search for products using Elasticsearch.

我遇到的问题之一是搜索查询中经常包含隐含的术语.例如,请考虑当有人键入"lenovo thinkpad电池"时,他们需要电池.但是,当某人只键入"lenovo thinkpad"时,他们想要一台笔记本电脑,即使该词条未出现在查询中.

One of the problems that I'm having is that often search queries have implied terms. For example, consider that when someone types in "lenovo thinkpad battery" they want a battery. However, when someone types in just "lenovo thinkpad" they want a laptop, even though that term doesn't appear in the query.

我对此的解决方法如下.手动整理一堆相关术语.例如,对于计算机/笔记本电脑类别,我可以使用术语电池",键盘",电源线",适配器",电缆",保护计划"等.在搜索查询中,我积极地提高了所有不包含这些术语的结果.

My solution for this is the following. Manually put together a bunch of related terms. For example, for the computer/laptop category I could have the terms "battery", "keyboard", "power cord", "adapter", "cable", "protection plan" etc. Then, whenever no such term is present in the search query, I positive boost all the results that don't contain those terms.

Elasticsearch有可能吗?

Is this possible with Elasticsearch?

示例文件

{"_source": { "item_title": "lenovo thinkpad white/black" },
 "_source": { "item_title": "lenovo thinkpad battery" }
}

映射

{
    "properties": {
        "item_title": {
            "type": "string"
        }
    }
}

查询

POST my_index/my_type/_search
{
    "from": 0, 
    "size": 10,
    "query": {
        "match": {
            "item_title": "lenovo thinkpad"
        }
    }
}

查询结果:

"hits": {
  "total": 2,
  "max_score": 0.2169777,
  "hits": [
     {
        "_index": "my_index",
        "_type": "my_type",
        "_id": "2",
        "_score": 0.2169777,
        "_source": {
           "item_title": "lenovo thinkpad battery"
        }
     },
     {
        "_index": "my_index",
        "_type": "my_type",
        "_id": "1",
        "_score": 0.2169777,
        "_source": {
           "item_title": "lenovo thinkpad black/white"
        }
     }
  ]
}

请注意,这两个结果的分数相同.但是,由于查询"lenovo thinkpad"不包含我手动选择的那些特殊术语之一(例如电池"),因此我希望不包含该术语的文档被增强为正,以便具有"item_title":联想Thinkpad白色/黑色"在查询结果中应该得分更高.

Notice that the score for these two results is the same. However, since the query "lenovo thinkpad" doesn't contain one of those special terms that I manually picked out, like "battery", I would like documents that don't contain that term to be positive boosted, so that the document with "item_title": "lenovo thinkpad white/black" should have higher score in the query results.

推荐答案

如果我在Wikipedia索引中执行以下查询

If I execute the Following Query in my Wikipedia index

GET /_search
{
   "query": {
      "query_string": {
         "query": "(Darmstadt)^10 (NOT School)^8",
         "fields": [
            "title^3"
         ],
         "phrase_slop": 3,
         "use_dis_max": true
      }
   }
}

我仍然在达姆施塔特学校的成绩中排名靠后(通常排在前十名中)

I Still get Darmstadt School in the results further down the list (it comes in the first 10 normally)

如果我执行以下查询

GET /_search
{
   "query": {
      "query_string": {
         "query": "(Darmstadt AND SCHOOL )^10 (NOT School)^8",
         "fields": [
            "title^3"
         ],
         "phrase_slop": 3,
         "use_dis_max": true
      }
   }
}

尽管不在NOT子句中,但我将达姆施塔特学校列为第一名.所以我建议你做类似的事情.

I Get Darmstadt School as the First result despite it being in the NOT clause. So I suggest you do something similar.

这篇关于Elasticsearch:没有任期时会积极推动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆