【问题标题】:ElasticSearch filter boosting based on field value基于字段值的 ElasticSearch 过滤器提升
【发布时间】:2013-01-04 17:48:39
【问题描述】:

我有以下疑问:

{
"from": 0, 
"query": {
    "custom_filters_score": {
        "filters": [
            {
                "boost": 1.5, 
                "filter": {
                    "term": {
                        "format": "test1"
                    }
                }
            }, 
            {
                "boost": 1.5, 
                "filter": {
                    "term": {
                        "format": "test2"
                    }
                }
            }
        ], 
        "query": {
            "bool": {
                "must": {
                    "query_string": {
                        "analyzer": "query_default", 
                        "fields": [
                            "title^5", 
                            "description^2", 
                            "indexable_content"
                        ], 
                        "query": "blah"
                    }
                }, 
                "should": []
            }
        }
    }
}, 
"size": 50
}

如果我正确阅读了文档,这应该会提升其中包含 {"format":"test1"} 的内容。

但是,使用explain 告诉我"custom score, no filter match, product of:" 是结果,并且与过滤器匹配的返回文档的分数不会被此过滤器更改。

我做错了什么?

编辑:这是架构:

mapping:
  edition:
    _all: { enabled: true }
    properties:
      title:       { type: string, index: analyzed }
      description: { type: string, index: analyzed }
      format:      { type: string, index: not_analyzed, include_in_all: false }
      section:     { type: string, index: not_analyzed, include_in_all: false }
      subsection:  { type: string, index: not_analyzed, include_in_all: false }
      subsubsection:  { type: string, index: not_analyzed, include_in_all: false }
      link:        { type: string, index: not_analyzed, include_in_all: false }
      indexable_content: { type: string, index: analyzed }

让我们假设一个典型的文档是这样的:

{
    "format": "test1",
    "title": "blah",
    "description": "blah",
    "indexable_content": "keywords here",
    "section": "section",
    "subsection": "child-section",
    "link":"/section/child-section/blah"
}

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    如果它显示“没有过滤器匹配”,则表示它不匹配您查询中的任何过滤器。最可能的原因是与您的查询匹配的记录中没有术语“test1”。不幸的是,您没有提供映射和测试数据,因此很难确定那里发生了什么。

    尝试运行此查询,看看您是否真的可以找到任何符合您的搜索条件并且应该被提升的记录:

    {
        "from": 0,
        "query": {
            "bool": {
                "must": [{
                    "query_string": {
                        "analyzer": "query_default",
                        "fields": ["title^5", "description^2", "indexable_content"],
                        "query": "blah"
                    }
                }, {
                    "term": {
                        "format": "test1"
                    }
                }]
            }
        },
        "size": 50
    }
    

    您的查询看起来不错,根据提供的信息,它应该可以工作:https://gist.github.com/4448954

    【讨论】:

    • 我已经更新了我的问题以包括架构和一个编辑过的示例文档,如果这有任何改变的话。
    • 我已经用您提供的信息更新了要点。它仍然有效。我用 0.20.2 对其进行了测试。所以,我猜你要么编辑了一些重要的信息,要么你正在使用一些旧版本的弹性搜索,这个功能被破坏了。您能否创建一个不适合您的完整复制品?
    • 原来我是个白痴,索引没有加载。毕竟查询确实有效!
    猜你喜欢
    • 2012-09-07
    • 2019-05-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-24
    相关资源
    最近更新 更多