Elasticsearch Java API Cont.

Source: Internet
Author: User

Tag: action-related int type string lookup att item exists

1. Use the multi Get API to get a collection of documents one at a time by index name, type name, and document ID, either from the same index library or from a different index library. Examples are as follows:

Multigetresponse multigetitemresponses = Client.preparemultiget (). Add ("Twitter", "tweet",  "1") //notes 1 . Add ( "tweet",  "2",  "3",  "4") //notes 2. Add (" another ", " type ", " foo ") //Note 3. get (); for (Multigetitemresponse itemresponse:multigetitemresponses) { //Note 4 GetResponse response = Itemresponse.getresponse (); if (response.isexists ()) {//comment 5 String json = Response.getsourceasstring (); //comment 6}}             

Note 1: Get a document with a single ID.

NOTE 2: Multiple IDs are passed in, and multiple documents are obtained from the same index name/type name.
Note 3: You can get documents from different indexes at the same time.
Note 4: Traverse the result set.
Note 5: Verify that the document exists.
Note 6: Get the document source.

2, in Java to implement a three-level parent-child relationship nested search, related information is very small, hair on the StackOverflow after a Switzerland of the great God soon replied to me, google+stackoverflow very good. corresponding command-line query:

{      "Query ":{        "Has_child ":{          "Type ":"Instance", "Query ":{"has_child": {"type": "Instance_permission", "query": {"terms": {"uuid": c11>{"index": "User", "type": "User", "ID": " 5", "path": "UUIDs"}}}}}}}< /c22> 

Java API:

Termslookupquerybuilder terms = querybuilders. Termslookupquery ("UUID"). Lookupindex ("User"). Lookuptype ("User"). LookupId ("5"). Lookuppath ("UUIDs"); Haschildquerybuilder hquery = querybuilders. Haschildquery ("Instance", Querybuilders. Haschildquery ("Instance_permission", terms)); System. Out. println ("Exectuing Query 1"); System. Out. println (Hquery. toString ()); SearchResponse searchResponse1 = Client.preparesearch ( "Foo_oa_hr_askforleave") .setquery (hquery) .execute ()  . Actionget () ; System.out.println ( " There were "+ Searchresponse1.gethits ()  "results found for Query 1.") .out.println (SearchResponse1.tostring ()) .out.println ()              

Elasticsearch Java API cont.

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.