【问题标题】:Elasticsearch function_score with nested_objects带有嵌套对象的 Elasticsearch function_score
【发布时间】:2014-08-07 12:46:04
【问题描述】:

我的查询有问题。我使用查询来提升没有嵌套对象的文档。现在我使用nested_objects 并将查询更改为使用嵌套过滤器,但没有任何提升。 我得到了我期望的文件,但没有 _score 变化。

我是不是做错了什么??

GET index/type/_search
{
   "query": {
      "function_score": {
         "filter": {
            "bool": {
               "must": [
                  {
                     "term": {
                        "parent.child": "test"
                     }
                  }
               ]
            }
         },
         "functions": [
            {
               "boost_factor": "100",
               "filter": {
                  "nested": {
                     "path": "parent",
                     "filter": {
                        "bool": {
                           "must": [
                              {
                                 "term": {
                                    "child": "test"
                                 }
                              }
                           ]
                        }
                     }
                  }
               }
            }
         ],
         "score_mode": "sum"
      }
   },
   "sort": "_score",
   "from": 0,
   "size": 320
}

编辑: 会不会是因为

嵌套过滤器

嵌套过滤器的行为很像嵌套查询,除了它 不接受 score_mode 参数。它只能用于 “过滤上下文” — 例如在过滤查询中 — 它的行为 像任何其他过滤器一样:它包含或排除,但它不得分。

虽然嵌套过滤器本身的结果没有被缓存,但 通常的缓存规则适用于嵌套过滤器内的过滤器。

http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/nested-query.html

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    正如文档所说:

    嵌套过滤器

    嵌套过滤器的行为很像嵌套查询,只是它不接受 score_mode 参数。它只能在“过滤上下文”中使用 — 例如在过滤查询中 —  并且它的行为类似于任何其他过滤器:它包含或排除,但它不得分

    虽然嵌套过滤器本身的结果不会被缓存,但通常的缓存规则适用于嵌套过滤器内的过滤器。

    http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/nested-query.html

    【讨论】:

      【解决方案2】:

      我觉得你的 JSON 应该看起来更接近这个(也许不完全是,我还没有测试过)。

      {
         "query": {
            "function_score": {
               "query": {
                 "nested": {
                     "path": "parent",
                     "query": {
                        "bool": {
                           "must": [
                              {
                                 "term": {
                                    "parent.child": "test"
                                 }
                              }
                           ]
                        }
                     }
                  }
               },
               "functions": [
                  {
                     "boost_factor": "100"
                  }
               ],
               "score_mode": "sum"
            }
         },
         "sort": "_score",
         "from": 0,
         "size": 320
      }
      

      具体来说,您不想过滤boost_factor,只想将此function_score 提高100。实际的嵌套查询位于function_scorequery 部分和functions部分只包含boost_factor。我想。

      【讨论】:

      • 如果我删除嵌套部分并提升根字段,查询将按预期工作。
      • 在嵌套查询中,不应该还是"parent.child": "test"而不是"child": "test"吗?就实际问题而言,对不起,我现在无法实际测试东西:(我会删除我的答案
      猜你喜欢
      • 1970-01-01
      • 2014-03-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多