Files
honeymoose f321dfedf5 同步完成!
**同步结果摘要**:

| 目录 | 同步前 | 同步后 | 官方 |
|------|--------|--------|------|
| aggregations | 40 | 65 | 64 |
| analyzers | 8 | 141 | 140 |
| api-reference | 97 | 186 | 174 |
| benchmark | 34 | 67 | 53 |
| clients | 17 | 18 | 18 |
| dashboards | 38 | 149 | 131 |
| data-prepper | 77 | 134 | 123 |
| im-plugin | 22 | 37 | 37 |
| ingest-pipelines | 27 | 52 | 51 |
| install-and-configure | 37 | 57 | 53 |
| ml-commons-plugin | 81 | 157 | 155 |
| observing-your-data | 39 | 73 | 66 |
| query-dsl | 40 | 77 | 75 |
| search-plugins | 80 | 139 | 95 |
| security-analytics | 22 | 47 | 46 |

**说明**:
- 本地文件数 > 官方:本地有一些官方已删除或重命名的文件
- 新增了约 **740 个英文文档文件**
- 已有文件保持不变(未覆盖)
2026-11-30 10:48:30 -05:00

2.5 KiB

layout, title, parent, grand_parent, nav_order
layout title parent grand_parent nav_order
default Span not Span queries Query DSL 60

Span not query

The span_not query excludes spans that overlap with another span query. You can also specify the distance before or after the excluded spans within which matches cannot occur.

For example, you can use the span_not query to:

  • Find terms except when they appear in certain phrases.
  • Match spans unless they are near specific terms.
  • Exclude matches that occur within a certain distance of other patterns.

Example

To try the examples in this section, complete the setup steps. {: .tip}

The following query searches for the word "dress" but not when it appears in the phrase "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
        }
      }
    }
  }
}

{% include copy-curl.html %}

The query matches document 2 because it contains the word "dress" ("Beautiful long dress..."). Document 1 is not matched because it contains the phrase "dress shirt", which is excluded. Documents 3 and 4 are not matched because they contain variations of the word "dress" ("dressed" and "dresses"), and the query is searching the raw field.

Response {: .text-delta}

Parameters

The following table lists all top-level parameters supported by span_not queries.

Parameter Data type Description
include Object The span query whose matches you want to find. Required.
exclude Object The span query whose matches should be excluded. Required.
pre Integer Specifies that the exclude span cannot appear within the given number of token positions before the include span. Optional. Default is 0.
post Integer Specifies that the exclude span cannot appear within the given number of token positions after the include span. Optional. Default is 0.
dist Integer Equivalent to setting both pre and post to the same value. Optional.