【问题标题】:Elasticsearch Multiple Prefix query OR MatchingElasticsearch 多前缀查询或匹配
【发布时间】:2018-09-14 06:30:57
【问题描述】:

我想完成以下任务(表示为等效的 SQL 查询)

WHERE field1 LIKE 'FOO%' OR field2 LIKE 'FOO%'

但是说boost field2(即如果一个文档只有两个字段中的一个)匹配 field2 的文档会被提升

如何在 Elasticsearch 中实现这一点?我没完没了地翻阅文档,只是越来越困惑

我试过了:

POST securities/_search
{
  "query": {
    "bool": {
      "minimum_should_match": 1, 
      "should": [
        {
            "match_phrase_prefix": {
              "field2": "FOO"
            }
        },
        {
          "match_phrase_prefix": {
              "field2": "FOO"
          }
        }
      ]
    }
  }
}

但我无法从 bool.should[*].match_phrase_prefix

中指定提升

我看到我可以在 bool 级别指定一个 boost 属性,但我不确定它是如何应用的

【问题讨论】:

  • 您的示例中有 2 次“field2”。我认为第一个应该是“field1”

标签: elasticsearch


【解决方案1】:

为了让它工作,你应该改变这个:

"match_phrase_prefix": {
    "field2": "FOO"
}

到这里:

"match_phrase_prefix": {
    "field2": {
        "value": "FOO",
        "boost": 2.0
    }
}

这应该是提升的正确语法。

【讨论】:

  • 我看到 boost 是在 2015 年的 PR 中添加的,不知何故不是 Kibana 自动完成的一部分,谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-10-21
  • 2013-11-10
  • 1970-01-01
  • 2017-06-30
  • 1970-01-01
相关资源
最近更新 更多