filter-query中的弹性bool查询始终为零分

时间:2017-05-11 07:35:19

标签: elasticsearch nest

我的弹性查询有一个奇怪的问题,我无法弄清楚。我对Elastic很新鲜。

我有以下查询来搜索我的索引:

GET frow_local_commerce_master_a1/product/_search
{
  "query": {
    "bool": {
      "should": [
        {
          "query_string": {
            "default_field": "commercialCode",
            "query": "*UE1406* OR UE1406~",
            "allow_leading_wildcard": true,
            "fuzziness": 2,
            "default_operator": "OR",
            "boost": 100
          }
        },
        {
          "query_string": {
            "query": "*UE1406*",
            "allow_leading_wildcard": true,
            "fields": [
              "range^2.0"
            ],
            "default_operator": "OR"
          }
        },
        {
          "nested": {
            "path": "localized",
            "query": {
              "query_string": {
                "query": "*UE1406*",
                "allow_leading_wildcard": true,
                "fields": [
                  "localized.floorType^2.0",
                  "localized.productName^3.0"
                ],
                "default_operator": "OR"
              }
            }
          }
        }
      ]
    }
  }
}

这可以按预期工作。没问题,但问题是每当我用过滤查询扩展这个主查询时:

GET frow_local_commerce_master_a1/product/_search
{
  "query": {
    "bool": {
      "filter": [
        {
          "term": {
            "brand.keyword": {
              "value": "QS"
            }
          }
        },
        {
          "query": {
            "bool": {
              "should": [
                {
                  "query_string": {
                    "default_field": "commercialCode",
                    "query": "*UE1406* OR UE1406~",
                    "allow_leading_wildcard": true,
                    "fuzziness": 2,
                    "default_operator": "OR",
                    "boost": 100
                  }
                },
                {
                  "query_string": {
                    "query": "*UE1406*",
                    "allow_leading_wildcard": true,
                    "fields": [
                      "range^2.0"
                    ],
                    "default_operator": "OR"
                  }
                },
                {
                  "nested": {
                    "path": "localized",
                    "query": {
                      "query_string": {
                        "query": "*UE1406*",
                        "allow_leading_wildcard": true,
                        "fields": [
                          "localized.floorType^2.0",
                          "localized.productName^3.0"
                        ],
                        "default_operator": "OR"
                      }
                    }
                  }
                }
              ]
            }
          }
        },
        {
          "nested": {
            "query": {
              "bool": {
                "filter": [
                  {
                    "term": {
                      "localized.language.keyword": {
                        "value": "nl-BE"
                      }
                    }
                  }
                ]
              }
            },
            "path": "localized"
          }
        }
      ]
    }
  }
}

正如您所看到的,此查询与第一个查询相同,但有一个“查询” - >在它上面“过滤”。我需要这个,因为我需要在主搜索查询旁边过滤其他属性。

问题是这个查询总是有一个_score 0.每当我运行第一个查询时,我都有一个正常的分数..

当我执行第二个查询时,有没有人知道为什么我的_score总是为零?什么可能是解决方案?

提前致谢。

0 个答案:

没有答案