我有两个有关ElasticSearch的问题。
1)第一个问题,我有一个带前缀的查询
"must": [
{
"prefix": {
"user": "John"
}
}
]通过这个查询,我可以使用前缀 John 和用户字段,从而得到那些在用户字段中找到John的文档。现在,我如何进行此查询,以查看用户或电子邮件字段中是否有前缀。
2)第二个问题,我知道我们可以在ElasticSearch中应用Size和from来限制结果,但我想知道我是否必须显式地提供Size,从每次在ElasticSearch中查询来继续最后的结果时起,还是有其他方法让ElasticSearch为我做它,而我只是查询它,它将给出以前的系列中的结果。
发布于 2013-12-31 14:26:23
首先,请注意,prefix-query不进行任何文本分析,因此您将不会将john与查询匹配。
您应该查看匹配-query,它也使用匹配-query的选项。因此,您可以将multi_match与phrase_prefix结合起来,并从中获得最佳效果:多个字段上的匹配和文本分析。
下面是一个可以运行的示例: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。
https://stackoverflow.com/questions/20858404
复制相似问题