Elasticsearch 等于 SQL %Like%

Elasticsearch equal SQL %Like%

来自 here 我问自己此类查询的 elasticsearch 语法:

WHERE text LIKE "%quick%"
  AND text LIKE "%brown%"
  AND text LIKE "%fox%" 

我的尝试(遗憾的是没有成功)

  "query": {
    "bool": {
      "filter": [
        {
          "bool": {
            "must": [
              {
                "terms": {
                  "text": [
                    "*quick*",
                    "*brown*",
                    "*fox*"
                  ]
                }
              }
            ]
          }
        }
      ]
    }
  }

尝试使用 boolwildcard 进行这样的查询。

{
    "query": {
        "bool": {
            "must": [
                {
                    "wildcard": {
                        "text": "*quick*"
                    }
                },
                {
                    "wildcard": {
                        "text": "*brown*"
                    }
                },
                {
                    "wildcard": {
                        "text": "*fox*"
                    }
                }
            ]
        }
    }
}

Wildcard Query Matches documents that have fields matching a wildcard expression (not analyzed). Supported wildcards are *, which matches any character sequence (including the empty one), and ?, which matches any single character.

这就是您要找的。只需将所需数量的通配符查询放入 bool/must:

{
  "query": {
    "bool": {
      "must": [
        {
          "wildcard": {
            "text": {
              "value": "*quick*"
            }
          }
        },
        {
          "wildcard": {
            "text": {
              "value": "*brown*"
            }
          }
        },
        {
          "wildcard": {
            "text": {
              "value": "*fox*"
            }
          }
        }
      ]
    }
  }
}