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.8 KiB

layout, title, parent, grand_parent, nav_order
layout title parent grand_parent nav_order
default Span within Span queries Query DSL 90

Span within query

The span_within query matches spans that are enclosed by another span query. It is the opposite of span_containing: span_containing returns larger spans containing smaller ones, whereas span_within returns smaller spans enclosed by larger ones.

For example, you can use the span_within query to:

  • Find shorter phrases that appear within longer phrases.
  • Match terms that occur within specific contexts.
  • Identify smaller patterns enclosed by larger patterns.

Example

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

The following query searches for the word "dress" when it appears within a span containing "shirt" and "long":

GET /clothing/_search
{
  "query": {
    "span_within": {
      "little": {
        "span_term": {
          "description": "dress"
        }
      },
      "big": {
        "span_near": {
          "clauses": [
            {
              "span_term": {
                "description": "shirt"
              }
            },
            {
              "span_term": {
                "description": "long"
              }
            }
          ],
          "slop": 2,
          "in_order": false
        }
      }
    }
  }
}

{% include copy-curl.html %}

The query matches document 1 because:

  • The word "dress" appears within a larger span ("Long-sleeved dress shirt...").
  • The larger span contains "shirt" and "long" within 2 words of each other (there are 2 words between them).
Response {: .text-delta}
{
  "took": 3,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 1,
      "relation": "eq"
    },
    "max_score": 1.4677674,
    "hits": [
      {
        "_index": "clothing",
        "_id": "1",
        "_score": 1.4677674,
        "_source": {
          "description": "Long-sleeved dress shirt with a formal collar and button cuffs. "
        }
      }
    ]
  }
}

Parameters

The following table lists all top-level parameters supported by span_within queries. All parameters are required.

Parameter Data type Description
little Object The span query that must be contained within the big span. This defines the span you're searching for within a larger context.
big Object The containing span query that defines the boundaries within which the little span must appear. This establishes the context for your search.