【问题标题】:_score while doing indexing in elasticsearch在弹性搜索中进行索引时的_score
【发布时间】:2013-07-02 06:33:16
【问题描述】:
{
  "query": {
    "custom_score": {
      "query": {
        "match": {
          "xxx": {
            "query": "foobar"
          }
        }
      },
      "filter": {
        "and": [
          {
            "query": {
              "match": {
                "yyyy": {
                  "query": "barfoo"
                }
              }
            }
          }
        ]
      }
    },
    "script": "_score * doc['_score']"
  }
}

这会出错

 [custom_score] query does not support [filter]

那么如何评估这样的查询呢?

【问题讨论】:

  • 你的意思是索引时间提升吗?您能否详细说明您想要实现的目标?
  • 更新了问题。
  • 谢谢,但我不明白 :) 你能解释一下你想用你的脚本实现什么吗?我认为您应该重新表述您的问题,因为它不是在建立索引时而是在增加查询时间。此外,如果您再次查看您的异常,您应该会发现一条更详细的消息,其中包含查询失败的原因。
  • 更新了我的问题以清除它

标签: php elasticsearch


【解决方案1】:

我建议您查看有关提升的要求,因为您当前的脚本没有多大意义。

另外,请查看 elasticsearch query DSL 的文档。它提供复合查询和简单查询,您可以将它们组合在一起。正如错误所说,您不能在自定义分数查询中放置过滤器。您可以在自定义分数查询中使用filtered query

{
  "query": {
    "custom_score": {
      "query": {
        "filtered" : {
          "query" : {
            "match": {
              "xxx": {
                "query": "foobar"
              }
            }
          },
          "filter" : {
            "and": [
              {
                "query": {
                  "match": {
                    "yyyy": {
                      "query": "barfoo"
                    }
                  }
                }
              }
            ]
          }
        }
      },
      "script": "_score * doc['_score']"
    }
  }
}

或像这样使用顶级filter

{
  "query": {
    "custom_score": {
      "query": {
        "match": {
          "xxx": {
            "query": "foobar"
          }
        }
      },
      "script": "_score * doc['_score']"
    }
  },
  "filter": {
    "and": [
      {
        "query": {
          "match": {
            "yyyy": {
              "query": "barfoo"
            }
          }
        }
      }
    ]
  }
}

这两个选项之间的区别在于,如果您在搜索请求中也创建了分面,则不会考虑顶级过滤器,而如果您将过滤器放在查询中,则会考虑它们。

另一件需要注意的事情:如果您只有一个子句,则不需要 and 过滤器。此外,将全文搜索放在过滤器中通常没有意义,因为过滤器是可缓存的,并且鉴于全文搜索是免费的且几乎不可预测,缓存它们将是一种浪费。

【讨论】:

  • “script”属性应该在“custom_score”属性的括号内,而不是在它之外。感谢您在 SO 中提供的各种示例,非常有帮助。
  • 感谢@TedAvery 指出这一点,我编辑了我的答案。
猜你喜欢
  • 1970-01-01
  • 2014-06-07
  • 2016-03-14
  • 2016-06-20
  • 1970-01-01
  • 2016-10-24
相关资源
最近更新 更多