Link Search Menu Expand Document Documentation Menu

Span not query

span_not 查询排除与另一个跨度查询重叠的跨度。您还可以指定排除跨度前后不允许出现匹配项的距离。

例如,您可以使用 span_not 查询来

  • 查找词条,除非它们出现在特定短语中。
  • 匹配跨度,除非它们靠近特定词条。
  • 排除在其他模式的特定距离内出现的匹配项。

示例

要尝试本节中的示例,请完成设置步骤

以下查询搜索单词“dress”,但排除其出现在短语“dress shirt”中

GET /clothing/_search
{
  "query": {
    "span_not": {
      "include": {
        "span_term": {
          "description": "dress"
        }
      },
      "exclude": {
        "span_near": {
          "clauses": [
            {
              "span_term": {
                "description": "dress"
              }
            },
            {
              "span_term": {
                "description": "shirt"
              }
            }
          ],
          "slop": 0,
          "in_order": true
        }
      }
    }
  }
}

该查询匹配文档 2,因为它包含单词“dress”(“Beautiful long dress…”)。文档 1 不匹配,因为它包含被排除的短语“dress shirt”。文档 3 和 4 不匹配,因为它们包含单词“dress”的变体(“dressed”和“dresses”),并且查询正在搜索原始字段。

响应

参数

下表列出了 span_not 查询支持的所有顶级参数。

参数 数据类型 描述
include 对象 您要查找其匹配项的跨度查询。必填。
exclude 对象 应排除其匹配项的跨度查询。必填。
pre 整数 指定 exclude 跨度不能出现在 include 跨度之前的给定词元位置数内。可选。默认值为 0
post 整数 指定 exclude 跨度不能出现在 include 跨度之后的给定词元位置数内。可选。默认值为 0
dist 整数 等同于将 prepost 都设置为相同值。可选。
剩余 350 字符

有问题?

想要贡献?