Multiple Fields for Prefix in ElasticSearch and auto From and Size limit
First, note that the prefix
-query does not do any text analysis, so you will not be matching e.g. john
with your query.
You should look into the multi_match-query which takes the options of the match-query as well. Thus, you can combine multi_match
with phrase_prefix
and get the best of both: matching on multiple fields, and text analysis.
Here is a runnable example you can play with: https://www.found.no/play/gist/8197442
#!/bin/bashexport ELASTICSEARCH_ENDPOINT="http://localhost:9200"# Index documentscurl -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 searchescurl -XPOST "$ELASTICSEARCH_ENDPOINT/_search?pretty" -d '{ "query": { "multi_match": { "fields": [ "user", "email" ], "query": "john", "operator": "and", "type": "phrase_prefix" } }}'
For your second question, look into the scroll API.