Introduction to Elasticsearch's _msearch and its use in Ruby on Rails

Source: Internet
Author: User
Tags ruby on rails


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


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.