You're viewing an archived version of our docs. Check out our current documentation →

Run a Composition

Runs a query on a single composition and returns matching results.

Usage

Required ACL: search
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import com.algolia.api.CompositionClient;
import com.algolia.config.*;

CompositionClient client = new CompositionClient("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY");

client.search(
  "foo",
  new RequestBody().setParams(
      new Params()
        .setQuery("batman")
        .setInjectedItems(
          new HashMap() {
            {
              put(
                "injectedItem1",
                new ExternalInjectedItem().setItems(
                    Arrays.asList(
                      new ExternalInjection().setObjectID("my-object-1"),
                      new ExternalInjection()
                        .setObjectID("my-object-2")
                        .setMetadata(
                          new HashMap() {
                            {
                              put("my-string", "string");
                              put("my-bool", true);
                              put("my-number", 42);
                              put(
                                "my-object",
                                new HashMap() {
                                  {
                                    put("sub-key", "sub-value");
                                  }
                                }
                              );
                            }
                          }
                        )
                    )
                  )
              );
            }
          }
        )
    ),
  Hit.class
);