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.