Query DSL - Prefix Query

Prefix Query

前缀查询

Returns documents that contain a specific prefix in a provided field.

返回在指定字段中包含特定前缀的文档。

Example request

The following search returns documents where the user field contains a term that begins with ki.

下面搜索返回user字段中包含ki开头的词条的文档。

GET /_search
{
    "query": {
        "prefix": {
            "user": {
                "value": "ki"
            }
        }
    }
}

Copy as cURLView in Console

Top-level parameters for prefix

  • field

    (Required, object) Field you wish to search.

    (必填,对象)您要搜索的字段。

Parameters for field

field的参数

  • value

    (Required, string) Beginning characters of terms you wish to find in the provided field.

    (必需,字符串)您希望在field中找到的词条开头字符。

  • rewrite

    (Optional, string) Method used to rewrite the query. For valid values and more information, see the rewrite parameter.

    (可选,字符串)用于重写查询的方法。其有效值和更多信息,请参阅rewrite参数

Notes

笔记

Short request example

简化请求示例

You can simplify the prefix query syntax by combining the field and value parameters. For example:

您可以通过组合fieldvalue参数来简化prefix查询的语法。例如:

GET /_search
{
    "query": {
        "prefix" : { "user" : "ki" }
    }
}

Copy as cURLView in Console

Speed up prefix queries

加速前缀查询

You can speed up prefix queries using the index_prefixes mapping parameter. If enabled, Elasticsearch indexes prefixes between 2 and 5 characters in a separate field. This lets Elasticsearch run prefix queries more efficiently at the cost of a larger index.

您可以使用mapping设置中的index_prefixes参数来加快前缀查询的速度。如果启用该参数,Elasticsearch只会为单独的字段索引2到5个字符的前缀。这使Elasticsearch在较大的索引上更有效率执行前缀查询,从而减少成本。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值