弹性搜索完全匹配 [英] Elastic search exact match

查看:136
本文介绍了弹性搜索完全匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用弹性搜索,并且有一个时间完全匹配发生的恶魔。我已经尝试过match,query_string等的各种组合,我没有得到任何结果或不好的结果。
查询如下所示:

I'm using elasticsearch and am having a devil of a time getting an exact match to happen. I've tried various combinations of match, query_string, etc, and I either get nothing or bad results. Query looks like this:

{
  "filter": {
    "term": {
      "term": "dog",
      "type": "main"
    }
  },
  "query": {
    "match_phrase": {
      "term": "Dog"
    }
  },
  "sort": [
    "_score"
  ]
}

排序结果

10.102211 {u'term': u'The Dog', u'type': u'main', u'conceptid': 7730506}
10.102211 {u'term': u'That Dog', u'type': u'main', u'conceptid': 4345664}
10.102211 {u'term': u'Dog', u'type': u'main', u'conceptid': 144}
7.147442 {u'term': u'Dog Eat Dog (song)', u'type': u'main', u'conceptid': u'5288184'}

我看到当然,狗,那只狗和狗都有相同的分数,但是我需要弄清楚我能如何提高比分狗的得分。

I see, of course that "The Dog", "That Dog" and "Dog" all have the same score, but I need to figure out how I can boost the exact match "Dog" in score.

我也试过

{
  "sort": [
    "_score"
  ],
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "term": "Dog"
          }
        },
        {
          "match_phrase": {
            "term": {
              "query": "Dog",
              "boost": 5
            }
          }
        }
      ]
    }
  },
  "filter": {
    "term": {
      "term": "dog",
      "type": "main"
    }
  }
}

但仍然只是给我

11.887239 {u'term': u'The Dog', u'type': u'main', u'conceptid': 7730506}
11.887239 {u'term': u'That Dog', u'type': u'main', u'conceptid': 4345664}
11.887239 {u'term': u'Dog', u'type': u'main', u'conceptid': 144}
8.410372 {u'term': u'Dog Eat Dog (song)', u'type': u'main', u'conceptid': u'5288184'}


推荐答案

默认情况下,使用标准分析器分析字段。如果你想检查完全匹配,你可以存储你的字段不分析,例如:

Fields are analyzed with the standard analyzer by default. If you would like to check exact match, you could store your field not analyzed also e.g:

"dog":{
            "type":"multi_field",
            "fields":{
                "dog":{
                    "include_in_all":false,
                    "type":"string",
                    "index":"not_analyzed",
                    "store":"no"
                },
                "_tokenized":{
                    "include_in_all":false,
                    "type":"string",
                    "index":"analyzed",
                    "store":"no"
                }
            }
        }

然后,您可以查询狗字段的完全匹配,dog._tokenized用于分析的查询(如全文)

Then you can query the dog-field for exact matches, and dog._tokenized for analyzed queries (like fulltext)

这篇关于弹性搜索完全匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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