Link Search Menu Expand Document Documentation Menu

Span within 查询

span_within 查询匹配被另一个 span 查询包含的 span。它与 span_containing 相反:span_containing 返回包含较小 span 的较大 span,而 span_within 返回被较大 span 包含的较小 span。

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

  • 查找出现在较长短语中的较短短语。
  • 匹配出现在特定上下文中的术语。
  • 识别被较大模式包含的较小模式。

示例

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

以下查询用于搜索当单词“dress”出现在包含“shirt”和“long”的 span 中时的情况

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
        }
      }
    }
  }
}

该查询匹配文档 1,因为

  • 单词“dress”出现在一个较大的 span 中(“Long-sleeved dress shirt…”)。
  • 较大的 span 包含“shirt”和“long”,它们之间相隔 2 个词(它们之间有 2 个词)。
响应
{
  "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. "
        }
      }
    ]
  }
}

参数

下表列出了 span_within 查询支持的所有顶级参数。所有参数均为必填项。

参数 数据类型 描述
little 对象 必须包含在 big span 中的 span 查询。这定义了您在较大上下文中搜索的 span。
big 对象 定义 little span 必须出现在其内部边界的包含 span 查询。这为您的搜索建立了上下文。
剩余 350 字符

有问题?

想要贡献?