繁体   English   中英

ElasticSearch中的前缀的多个字段以及自动起始和大小限制

[英]Multiple Fields for Prefix in ElasticSearch and auto From and Size limit

我有两个与ElasticSearch相关的问题。

1) 第一个问题 ,我有这个带有前缀的查询

"must": [
        {
           "prefix": {
              "user": "John"
           }
        }
     ]

使用此查询,我可以使用用户字段对John进行前缀 ,以便生成在“用户”字段中找到John的文档。 现在,我该如何进行此查询以查看John是否在任何用户或电子邮件字段中都有前缀。


2) 第二个问题 ,我知道我们可以应用规模 ElasticSearch限制的结果,但我想知道,我必须明确地规定尺寸 ,并每一次我在ElasticSearch查询继续最后的结果或时间有没有其他的办法让ElasticSearch为我做的只是查询,它将在前一个系列中给出结果。

首先,请注意prefix -query不会进行任何文本分析,因此您不会将john与查询匹配。

你应该看看multi_match -query它接受的选项匹配 -query为好。 因此,您可以将multi_matchphrase_prefix结合multi_match ,并充分利用两者:匹配多个字段和文本分析。

这是一个可以玩的可运行的例子: https//www.found.no/play/gist/8197442

#!/bin/bash

export ELASTICSEARCH_ENDPOINT="http://localhost:9200"

# Index documents
curl -XPOST "$ELASTICSEARCH_ENDPOINT/_bulk?refresh=true" -d '
{"index":{"_index":"play","_type":"type"}}
{"user":"John Smith","email":"john.smith@gmail.com"}
{"index":{"_index":"play","_type":"type"}}
{"user":"Alice Smith","email":"john.smith@gmail.com"}
'

# Do searches

curl -XPOST "$ELASTICSEARCH_ENDPOINT/_search?pretty" -d '
{
    "query": {
        "multi_match": {
            "fields": [
                "user",
                "email"
            ],
            "query": "john",
            "operator": "and",
            "type": "phrase_prefix"
        }
    }
}
'

关于第二个问题,请查看滚动 API。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM