First, the basic introduction
_msearch is the end of the multi search API that can execute multiple query requests in the same API.
The requested format resembles the format of the large API, and its request format is as follows:
header\n
body\n
header\n
body\n
The header can contain an index to query (which can be multiple indexes), an optional mapping type, andsearch_typepreference和routing。
The body can contain the specified search request (including: query, aggregations, from, size, and so on).
For example, see official website: https://www.elastic.co/guide/en/elasticsearch/reference/current/search-multi-search.html#search-multi-search
$ cat requests
{}
{"query" : {"match_all" : {}}, "from" : 0, "size" : 10}
{}
{"query" : {"match_all" : {}}}
{"index" : "test2"}
{"query" : {"match_all" : {}}}
$ curl -XGET localhost:9200/test/_msearch --data-binary @requests; echo
In the example, there is a requests file that transmits its contents to the past using Curl's binary stream.
The following is a practical example of transmitting files and JSON data:
In the current directory, create the file Requests,vim requests, write:
Save exit.
Curl-xpost ' Http://xxx.xxx.xxx:9200/_msearch?pretty '--data-binary @requests
The data will appear, indicating success:
The following is an example of a JSON parameter transfer:
With Curl-xpost ' Http://xxx.xxx.xxx:9200/_msearch?pretty '-h ' content-type:application/json '--data-binary ' json parameter ' The format request:
Also get results, note the format of JSON, be sure to have a newline, it is recommended to write in a text editor and then copy in.
Second, the use of _msearch in Ruby on Rails
This is mainly dependent on two gem packages: Elasticsearch-ruby and elasticsearch-rails.
The basic use of these two packages can go to GitHub to learn, here mainly to see the use of Msearch, in GitHub search Msearch:
Look at the first two, one is the test, the other is the usage instructions. Instructions for use are as follows:
It is quite clear here that it passes our previous arguments in the form of an array: The body parameter, note that the body here is the named parameter.
Introduction to Elasticsearch's _msearch and its use in Ruby on Rails