Link Search Menu Expand Document Documentation Menu

Span term 查询

span_term 查询是最基本的跨度查询,它匹配包含单个词元的跨度。它作为更复杂的跨度查询的构建块。

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

  • 查找可在其他跨度查询中使用的精确词元匹配。
  • 匹配特定单词,同时保持位置信息。
  • 创建可与其他跨度查询结合使用的基本跨度。

示例

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

以下查询搜索精确词元“formal”

GET /clothing/_search
{
  "query": {
    "span_term": {
      "description": "formal"
    }
  }
}

或者,您可以在 value 参数中指定搜索词元

GET /clothing/_search
{
  "query": {
    "span_term": {
      "description": {
        "value": "formal"
      }
    }
  }
}

您还可以指定一个 boost 值来提升文档得分

GET /clothing/_search
{
  "query": {
    "span_term": {
      "description": {
        "value": "formal",
        "boost": 2
      }
    }
  }
}

此查询匹配文档 1 和 2,因为它们包含精确词元“formal”。位置信息被保留,以便在其他跨度查询中使用。

响应
{
  "took": 2,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 2,
      "relation": "eq"
    },
    "max_score": 1.498922,
    "hits": [
      {
        "_index": "clothing",
        "_id": "2",
        "_score": 1.498922,
        "_source": {
          "description": "Beautiful long dress in red silk, perfect for formal events."
        }
      },
      {
        "_index": "clothing",
        "_id": "1",
        "_score": 1.4466847,
        "_source": {
          "description": "Long-sleeved dress shirt with a formal collar and button cuffs. "
        }
      }
    ]
  }
}

参数

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

参数 数据类型 描述
<field> 字符串或对象 要搜索的字段名称。
剩余 350 字符

有问题?

想贡献?