0

Sql 查询是 EL 7.3 提供的一个非常棒的工具。但是我无法解释该错误:

当我将 SUM 与 Match 1 条件一起使用时,下面的查询效果很好

POST _xpack/sql?format=txt
{
"query":"SELECT SUM(FlightTimeHour) Avg_Flight_Time FROM flights where MATCH(OriginCountry,'AE') "
}

但是,如果我使用 2 个或更多条件,则下面的 SUM 和 MATCH 查询将失败:

POST _xpack/sql?format=txt
{
"query":"SELECT SUM(FlightTimeHour) Avg_Flight_Time FROM flights where MATCH(OriginCountry,'AE') OR MATCH(OriginCountry,'FR') "
}

有人可以告诉我出了什么问题吗?

4

1 回答 1

0

SQL 文档没有提到 MATCH 上的布尔运算符。我不认为它被支持。

您可以执行上述搜索如下 1. 使用查询而不是匹配进行全文搜索

"query": "SELECT SUM(FlightTimeHour) Avg_Flight_Time FROM flights where  QUERY('OriginCountry: AE OR OriginCountry: FR')"
  1. 执行关键字搜索
"query": "SELECT SUM(FlightTimeHour) Avg_Flight_Time FROM flights where OriginCountry.keyword='AE' OR OriginCountry.keyword='FR'"

编辑:以上查询为弹性搜索

GET fonds/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "multi_match": {
            "query": "bordeaux",
            "fields": [
              "IDEE",
              "SLOGAN",
              "NOM",
              "ADRESSE",
              "VILLE",
              "ACTIVITE1",
              "ACTIVITE2",
              "KEYWORDS",
              "KEYWORDS_SITE",
              "SITE_H1_H6",
              "DESCRIPTION",
              "DESCRIPTION_SITE",
              "ACTIVITE3",
              "BUSINESS_MODEL",
              "COLORS"
            ]
          }
        },
        {
          "range": {
            "FONDS_LEVEES_TOTAL": {
              "gt": 0
            }
          } 
        },
        {
          "script": {
            "script": "doc['COMPE_RESULTAT_CA_2000'].value + doc['COMPE_RESULTAT_CA_2001'].value>0"
          }
        }
      ]
    }
  },
  "aggs": {
    "SUM": {
      "sum": {
        "field": "FONDS_LEVEES_TOTAL"
      }
    }
  }
}
于 2019-09-26T03:53:42.140 回答