forked from meilisearch/meilisearch-java
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.code-samples.meilisearch.yaml
683 lines (660 loc) · 23.8 KB
/
.code-samples.meilisearch.yaml
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
# This code-samples file is used by the Meilisearch documentation
# Every example written here will be automatically fetched by
# the documentation on build
# You can read more on https://github.com/meilisearch/documentation/tree/master/.vuepress/code-samples
---
get_one_index_1: |-
client.getIndex("movies");
list_all_indexes_1: |-
client.getAllIndexes();
create_an_index_1: |-
client.createIndex("movies", "id");
update_an_index_1: |-
client.updateIndex("movies", "id");
delete_an_index_1: |-
client.deleteIndex("movies");
get_one_document_1: |-
client.index("movies").getDocument("25684");
get_documents_1: |-
client.index("movies").getDocuments();
add_or_replace_documents_1: |-
client.index("movies").addDocuments("[{"
+ "\"id\": 287947,"
+ "\"title\": \"Shazam\","
+ "\"poster\": \"https://image.tmdb.org/t/p/w1280/xnopI5Xtky18MPhK40cZAGAOVeV.jpg\","
+ "\"overview\": \"A boy is given the ability to become an adult superhero in times of need with a single magic word.\","
+ "\"release_date\": \"2019-03-23\""
+ "}]"
);
add_or_update_documents_1: |-
client.index("movies").updateDocuments("[{
+ "\"id\": 287947,"
+ "\"title\": \"Shazam ⚡️\","
+ "\"genres\": \"comedy\""
+ "}]"
);
delete_all_documents_1: |-
client.index("movies").deleteAllDocuments();
delete_one_document_1: |-
client.index("movies").deleteDocument("25684");
delete_documents_1: |-
client.index("movies").deleteDocuments(Arrays.asList(new String[]
{
"23488",
"153738",
"437035",
"363869"
}));
search_post_1: |-
client.index("movies").search("American ninja");
get_task_by_index_1: |-
client.index("movies").getTask(1);
get_all_tasks_1: |-
client.getTasks();
get_task_1: |-
client.getTask(1);
get_all_tasks_by_index_1: |-
client.index("movies").getTasks();
get_one_key_1: |-
client.getKey("d0552b41536279a0ad88bd595327b96f01176a60c2243e906c52ac02375f9bc4");
get_all_keys_1: |-
client.getKeys();
create_a_key_1: |-
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
Date dateParsed = format.parse("2042-04-02T00:42:42Z");
Key keyInfo = new Key();
keyInfo.setDescription("Add documents: Products API key");
keyInfo.setActions(new String[] {"documents.add"});
keyInfo.setIndexes(new String[] {"products"});
keyInfo.setExpiresAt(dateParsed);
client.createKey(keyInfo);
update_a_key_1: |-
//Not yet implemented
delete_a_key_1: |-
client.deleteKey("d0552b41536279a0ad88bd595327b96f01176a60c2243e906c52ac02375f9bc4")
get_settings_1: |-
client.index("movies").getSettings();
update_settings_1: |-
Settings settings = new Settings();
settings.setRankingRules(
new String[] {
"typo",
"words",
"sort",
"proximity",
"attribute",
"exactness",
"release_date:desc",
"rank:desc"
});
settings.setDistinctAttribute("movie_id");
settings.setSearchableAttributes(
new String[] {
"title",
"overview",
"genres"
});
settings.setDisplayedAttributes(
new String[] {
"title",
"overview",
"genres",
"release_date"
});
settings.setStopWords(
new String[] {
"the",
"a",
"an"
});
settings.setSortableAttributes(
new String[] {
"title",
"release_date"
});
HashMap<String, String[]> synonyms = new HashMap<String, String[]>();
synonyms.put("wolverine", new String[] {"xmen", "logan"});
synonyms.put("logan", new String[] {"wolverine"});
settings.setSynonyms(synonyms);
client.index("movies").updateSettings(settings);
reset_settings_1: |-
client.index("movies").resetSettings();
get_synonyms_1: |-
client.index("movies").getSynonyms();
update_synonyms_1: |-
HashMap<String, String[]> synonyms = new HashMap<String, String[]>();
synonyms.put("wolverine", new String[] {"xmen", "logan"});
synonyms.put("logan", new String[] {"wolverine"});
client.index("movies").updateSynonymsSettings(synonyms);
reset_synonyms_1: |-
client.index("movies").resetSynonymsSettings();
get_stop_words_1: |-
client.index("movies").getStopWords();
update_stop_words_1: |-
client.index("movies").updateStopWordsSettings(new String[] {"of", "the", "to"});
reset_stop_words_1: |-
client.index("movies").resetStopWordsSettings();
get_ranking_rules_1: |-
client.index("movies").getRankingRules();
update_ranking_rules_1: |-
Settings settings = new Settings();
settings.setRankingRules(new String[]
{
"words",
"typo",
"proximity",
"attribute",
"sort",
"exactness",
"release_date:asc",
"rank:desc"
});
client.index("movies").updateSettings(settings);
reset_ranking_rules_1: |-
client.index("movies").resetRankingRuleSettings();
get_distinct_attribute_1: |-
client.index("shoes").getDistinctAttribute();
update_distinct_attribute_1: |-
client.index("shoes").updateDistinctAttributeSettings("skuid");
reset_distinct_attribute_1: |-
client.index("shoes").resetDistinctAttributeSettings();
get_searchable_attributes_1: |-
client.index("movies").getSearchableAttributes();
update_searchable_attributes_1: |-
client.index("movies").updateSearchableAttributesSettings(new String[]
{
"title",
"overview",
"genres"
});
reset_searchable_attributes_1: |-
client.index("movies").resetSearchableAttributesSettings();
get_filterable_attributes_1: |-
client.index("movies").getFilterableAttributes();
update_filterable_attributes_1: |-
Settings settings = new Settings();
settings.setFilterableAttributes(new String[] {"genres", "director"});
client.index("movies").updateSettings(settings);
reset_filterable_attributes_1: |-
//Not yet implemented
get_displayed_attributes_1: |-
client.index("movies").getDisplayedAttributes();
update_displayed_attributes_1: |-
client.index("movies").updateDisplayedAttributesSettings(new String[]
{
"title",
"overview",
"genres",
"release_date"
});
reset_displayed_attributes_1: |-
client.index("movies").resetDisplayedAttributesSettings();
get_typo_tolerance_1:
client.index("books").getTypoToleranceSettings();
update_typo_tolerance_1: |-
TypoTolerance typoTolerance = new TypoTolerance();
HashMap<String, Integer> minWordSizeTypos =
new HashMap<String, Integer>() {
{
put("oneTypo", 4);
put("twoTypos", 10);
}
};
typoTolerance.setMinWordSizeForTypos(minWordSizeTypos);
typoTolerance.setDisableOnAttributes(new String[] {"title"});
client.index("books").updateTypoToleranceSettings(typoTolerance);
reset_typo_tolerance_1: |-
client.index("books").resetTypoToleranceSettings();
get_index_stats_1: |-
client.index("movies").getStats();
get_indexes_stats_1: |-
client.getStats();
get_health_1: |-
client.health();
get_version_1: |-
client.getVersion();
distinct_attribute_guide_1: |-
Settings settings = new Settings();
settings.setDistinctAttribute("product_id");
client.index("jackets").updateSettings(settings);
field_properties_guide_searchable_1: |-
Settings settings = new Settings();
settings.setSearchableAttributes(new String[]
{
"title",
"overview",
"genres"
});
client.index("movies").updateSettings(settings);
field_properties_guide_displayed_1: |-
Settings settings = new Settings();
settings.setDisplayedAttributes(new String[]
{
"title",
"overview",
"genres",
"release_date"
});
client.index("movies").updateSettings(settings);
filtering_guide_1: |-
SearchRequest searchRequest =
new SearchRequest("Avengers").setFilter(new String[] {"release_date > \"795484800\""});
client.index("movies").search(searchRequest);
filtering_guide_2: |-
SearchRequest searchRequest =
new SearchRequest("Batman").setFilter(new String[] {"release_date > 795484800 AND (director = \"Tim Burton\" OR director = \"Christopher Nolan\")"});
client.index("movies").search(searchRequest);
filtering_guide_3: |-
SearchRequest searchRequest =
new SearchRequest("Planet of the Apes").setFilter(new String[] {"rating >= 3 AND (NOT director = \"Tim Burton\")"});
client.index("movies").search(searchRequest);
search_parameter_guide_query_1: |-
client.index("movies").search("shifu");
search_parameter_guide_offset_1: |-
SearchRequest searchRequest = new SearchRequest("shifu").setOffset(1);
client.index("movies").search(searchRequest);
search_parameter_guide_limit_1: |-
SearchRequest searchRequest = new SearchRequest("shifu").setLimit(2);
client.index("movies").search(searchRequest);
search_parameter_guide_retrieve_1: |-
SearchRequest searchRequest =
new SearchRequest("a").setAttributesToRetrieve(new String[] {"overview", "title"});
client.index("movies").search(searchRequest);
search_parameter_guide_crop_1: |-
SearchRequest searchRequest =
new SearchRequest("shifu")
.setAttributesToCrop(new String[] {"overview"})
.setCropLength(5);
client.index("movies").search(searchRequest);
search_parameter_guide_crop_marker_1: |-
SearchRequest searchRequest =
new SearchRequest("shifu")
.setAttributesToCrop(new String[] {"overview"})
.setCropMarker("[…]");
client.index("movies").search(searchRequest);
search_parameter_guide_highlight_1: |-
SearchRequest searchRequest =
new SearchRequest("winter feast").setAttributesToHighlight(new String[] {"overview"});
client.index("movies").search(searchRequest);
search_parameter_guide_highlight_tag_1: |-
SearchRequest searchRequest =
new SearchRequest("winter feast")
.setAttributesToHighlight(new String[] {"overview"})
.setHighlightPreTag("<span class=\"highlight\">")
.setHighlightPostTag("</span>");
client.index("movies").search(searchRequest);
search_parameter_guide_matches_1: |-
SearchRequest searchRequest = new SearchRequest("winter feast").setMatches(true);
SearchResult searchResult = index.search(searchRequest);
settings_guide_synonyms_1: |-
Settings settings = new Settings();
HashMap<String, String[]> synonyms = new HashMap<String, String[]>();
synonyms.put("sweater", new String[] {"jumper"});
synonyms.put("jumper", new String[] {"sweater"});
settings.setSynonyms(synonyms);
client.index("tops").updateSettings(settings);
settings_guide_stop_words_1: |-
Settings settings = new Settings();
settings.setStopWords(new String[]
{
"the",
"a",
"an"
});
client.index("movies").updateSettings(settings);
settings_guide_ranking_rules_1: |-
Settings settings = new Settings();
settings.setRankingRules(new String[]
{
"words",
"typo",
"proximity",
"attribute",
"sort",
"exactness",
"release_date:asc",
"rank_desc"
});
client.index("movies").updateSettings(settings);
settings_guide_distinct_1: |-
Settings settings = new Settings();
settings.setDistinctAttribute("product_id");
client.index("jackets").updateSettings(settings);
settings_guide_searchable_1: |-
Settings settings = new Settings();
settings.setSearchableAttributes(new String[]
{
"title",
"overview",
"genres"
});
client.index("movies").updateSettings(settings);
settings_guide_displayed_1: |-
Settings settings = new Settings();
settings.setDisplayedAttributes(new String[]
{
"title",
"overview",
"genres",
"release_date"
});
client.index("movies").updateSettings(settings);
settings_guide_sortable_1: |-
Settings settings = new Settings();
settings.setSortableAttributes(new String[]
{
"price",
"author",
});
client.index("books").updateSettings(settings);
settings_guide_typo_tolerance_1: |-
TypoTolerance typoTolerance = new TypoTolerance();
HashMap<String, Integer> minWordSizeTypos =
new HashMap<String, Integer>() {
{
put("twoTypos", 12);
}
};
typoTolerance.setMinWordSizeForTypos(minWordSizeTypos);
typoTolerance.setDisableOnAttributes(new String[] {"title"});
client.index("movies").updateTypoToleranceSettings(typoTolerance);
typo_tolerance_guide_1: |-
TypoTolerance typoTolerance = new TypoTolerance();
typoTolerance.setEnabled(false);
client.index("movies").updateTypoToleranceSettings(typoTolerance);
typo_tolerance_guide_2: |-
TypoTolerance typoTolerance = new TypoTolerance();
typoTolerance.setDisableOnAttributes(new String[] {"title"});
client.index("movies").updateTypoToleranceSettings(typoTolerance);
typo_tolerance_guide_3: |-
TypoTolerance typoTolerance = new TypoTolerance();
typoTolerance.setDisableOnWords(new String[] {"shrek"});
client.index("movies").updateTypoToleranceSettings(typoTolerance);
typo_tolerance_guide_4: |-
TypoTolerance typoTolerance = new TypoTolerance();
HashMap<String, Integer> minWordSizeTypos =
new HashMap<String, Integer>() {
{
put("oneTypo", 4);
put("twoTypos", 10);
}
};
typoTolerance.setMinWordSizeForTypos(minWordSizeTypos);
client.index("movies").updateTypoToleranceSettings(typoTolerance);
documents_guide_add_movie_1: |-
client.index("movies").addDocuments("[{"
+ "\"movie_id\": 123sq178,"
+ "\"title\": \"Amelie Poulain\""
+ "}]"
);
getting_started_add_documents_md: |-
**Maven**
Add the following code to the `<dependencies>` section of your project:
```xml
<dependency>
<groupId>com.meilisearch.sdk</groupId>
<artifactId>meilisearch-java</artifactId>
<version>0.7.2</version>
<type>pom</type>
</dependency>
```
**Gradle**
Add the following line to the `dependencies` section of your `build.gradle`:
```groovy
implementation 'com.meilisearch.sdk:meilisearch-java:0.7.2'
```
```java
import com.meilisearch.sdk;
import java.nio.file.Files;
import java.nio.file.Path;
Path fileName = Path.of("movies.json");
String moviesJson = Files.readString(fileName);
Client client = new Client(new Config("http://127.0.0.1:7700", "masterKey"));
Index index = client.index("movies");
index.addDocuments(moviesJson);
```
[About this SDK](https://github.com/meilisearch/meilisearch-java)
getting_started_check_task_status: |-
client.index("movies").getTask(0);
getting_started_search_md: |-
```java
client.index("movies").search("botman");
```
[About this SDK](https://github.com/meilisearch/meilisearch-java)
getting_started_add_meteorites: |-
import com.meilisearch.sdk;
import org.json.JSONArray;
import java.nio.file.Files;
import java.nio.file.Path;
Path fileName = Path.of("meteorites.json");
String meteoritesJson = Files.readString(fileName);
Client client = new Client(new Config("http://127.0.0.1:7700", "masterKey"));
client.index("meteorites").addDocuments(meteoritesJson);
getting_started_update_ranking_rules: |-
Settings settings = new Settings();
settings.setRankingRules(new String[]
{
"exactness",
"words",
"typo",
"proximity",
"attribute",
"sort",
"release_date:asc",
"rank:desc"
});
client.index("movies").updateSettings(settings);
getting_started_update_displayed_attributes: |-
Settings settings = new Settings();
settings.setDisplayedAttributes(new String[]
{
"title",
"overview",
"poster"
});
client.index("movies").updateSettings(settings);
getting_started_update_searchable_attributes: |-
Settings settings = new Settings();
settings.setSearchableAttributes(new String[]
{
"title"
});
getting_started_update_stop_words: |-
Settings settings = new Settings();
settings.setStopWords(new String[]
{
"the"
});
client.index("movies").updateSettings(settings);
getting_started_synonyms: |-
Settings settings = new Settings();
HashMap<String, String[]> synonyms = new HashMap<String, String[]>();
synonyms.put("winnie", new String[] {"piglet"});
synonyms.put("piglet", new String[] {"winnie"});
settings.setSynonyms(synonyms);
client.index("movies").updateSettings(settings);
getting_started_filtering: |-
SearchRequest searchRequest =
new SearchRequest("").setFilter(new String[] {"mass < 200"});
client.index("meteorites").search(searchRequest);
getting_started_geo_radius: |-
SearchRequest searchRequest =
new SearchRequest("").setFilter(new String[] {"_geoRadius(46.9480, 7.4474, 210000)"});
client.index("meteorites").search(searchRequest);
getting_started_geo_point: |-
SearchRequest searchRequest =
new SearchRequest("").setSort(new String[] {"_geoPoint(48.8583701,2.2922926):asc"});
client.index("meteorites").search(searchRequest);
getting_started_sorting: |-
SearchRequest searchRequest = new SearchRequest("")
.setFilter(new String[] {"mass < 200"})
.setSort(new String[] {"mass:asc"});
client.index("meteorites").search(searchRequest);
getting_started_configure_settings: |-
Settings settings = new Settings();
settings.setFilterableAttributes(new String[] {"mass", "_geo"});
settings.setSortableAttributes(new String[] {"mass", "_geo"});
client.index("meteorites").updateSettings(settings);
getting_started_communicating_with_a_protected_instance: |-
Client client = new Client(new Config("http://127.0.0.1:7700", "apiKey"));
client.index("movies").search(new SearchRequest(""));
faceted_search_update_settings_1: |-
client.index("movies").updateFilterableAttributesSettings(new String[]
{
"director",
"genres"
});
faceted_search_filter_1: |-
SearchRequest searchRequest =
new SearchRequest("thriller").setFilterArray(new String[][] {
new String[] {"genres = Horror", "genres = Mystery"},
new String[] {"director = \"Jordan Peele\""}});
client.index("movies").search(searchRequest);
faceted_search_facets_distribution_1: |-
SearchRequest searchRequest =
new SearchRequest("Batman").setFacetsDistribution(new String[] {"genres"});
client.index("movies").search(searchRequest);
faceted_search_walkthrough_filter_1: |-
SearchRequest searchRequest =
new SearchRequest("thriller").setFilterArray(new String[][] {
new String[] {"genres = Horror", "genres = Mystery"},
new String[] {"director = \"Jordan Peele\""}});
client.index("movies").search(searchRequest);
add_movies_json_1: |-
import com.meilisearch.sdk;
import org.json.JSONArray;
import java.nio.file.Files;
import java.nio.file.Path;
Path fileName = Path.of("movies.json");
String moviesJson = Files.readString(fileName);
Client client = new Client(new Config("http://127.0.0.1:7700", "masterKey"));
Index index = client.index("movies");
index.addDocuments(moviesJson);
landing_getting_started_1: |-
Client client = new Client(new Config("http://127.0.0.1:7700", "masterKey"));
client.index("movies").addDocuments("["
+ "{\"id\": 1, \"title\": \"Carol\"},"
+ "{\"id\": 2, \"title\": \"Wonder Woman\"},"
+ "{\"id\": 3, \"title\": \"Life of Pi\"},"
+ "{\"id\": 4, \"title\": \"Mad Max: Fury Road\"},"
+ "{\"id\": 5, \"title\": \"Moana\"},"
+ "{\"id\": 6, \"title\": \"Philadelphia\"}"
+ "]"
);
post_dump_1: |-
client.createDump();
get_dump_status_1: |-
client.getDumpStatus("20201101-110357260");
phrase_search_1: |-
client.index("movies").search("\"african american\" horror");
sorting_guide_update_sortable_attributes_1: |-
Settings settings = new Settings();
settings.setSortableAttributes(new String[] {"price", "author"});
client.index("books").updateSettings(settings);
sorting_guide_update_ranking_rules_1: |-
Settings settings = new Settings();
settings.setRankingRules(new String[]
{
"words",
"sort",
"typo",
"proximity",
"attribute",
"exactness"
});
client.index("books").updateSettings(settings);
sorting_guide_sort_parameter_1: |-
SearchRequest searchRequest = new SearchRequest("science fiction").setSort(new String[] {"price:asc"});
client.index("books").search(searchRequest);
sorting_guide_sort_parameter_2: |-
SearchRequest searchRequest = new SearchRequest("butler").setSort(new String[] {"author:desc"});
client.index("books").search(searchRequest);
get_sortable_attributes_1: |-
client.index("books").getSortableAttributes();
update_sortable_attributes_1: |-
Settings settings = new Settings();
settings.setSortableAttributes(new String[] {"price", "author"});
client.index("books").updateSettings(settings);
reset_sortable_attributes_1: |-
//Not yet implemented
search_parameter_guide_sort_1: |-
SearchRequest searchRequest = new SearchRequest("science fiction").setSort(new String[] {"price:asc"});
client.index("search_parameter_guide_sort_1").search(searchRequest);
geosearch_guide_filter_settings_1: |-
Settings settings = new Settings();
settings.setFilterableAttributes(new String[] {"_geo"});
client.index("restaurants").updateSettings(settings);
geosearch_guide_filter_usage_1: |-
SearchRequest searchRequest =
new SearchRequest("").setFilter(new String[] {"_geoRadius(45.472735, 9.184019, 2000)"});
client.index("restaurants").search(searchRequest);
geosearch_guide_filter_usage_2: |-
SearchRequest searchRequest =
new SearchRequest("").setFilter(new String[] {"_geoRadius(45.472735, 9.184019, 2000) AND type = pizza"});
client.index("restaurants").search(searchRequest);
geosearch_guide_sort_settings_1: |-
Settings settings = new Settings();
settings.setSortableAttributes(new String[] {"_geo"});
client.index("restaurants").updateSettings(settings);
geosearch_guide_sort_usage_1: |-
SearchRequest searchRequest =
new SearchRequest("").setSort(new String[] {"_geoPoint(48.8561446,2.2978204):asc"});
client.index("restaurants").search(searchRequest);
geosearch_guide_sort_usage_2: |-
SearchRequest searchRequest =
new SearchRequest("").setSort(new String[] {
"_geoPoint(48.8561446,2.2978204):asc",
"rating:desc",
});
client.index("restaurants").search(searchRequest);
primary_field_guide_update_document_primary_key: |-
client.updateIndex("books", "title");
primary_field_guide_create_index_primary_key: |-
client.createIndex("books", "reference_number");
primary_field_guide_add_document_primary_key: |-
client.index("books").addDocuments("[{"
+ "\"reference_number\": 2879,"
+ "\"title\": \"Diary of a Wimpy Kid\","
+ "\"author\": \"Jeff Kinney\","
+ "\"genres\": [\"comedy\", \"humor\"],"
+ "\"price\": 5.00"
+ "}]"
, "reference_number");
security_guide_search_key_1: |-
Client client = new Client(new Config("http://127.0.0.1:7700", "apiKey"));
client.index("patient_medical_records").search();
security_guide_update_key_1: |-
//Not yet implemented
security_guide_create_key_1: |-
Client client = new Client(new Config("http://127.0.0.1:7700", "masterKey"));
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
Date dateParsed = format.parse("2023-01-01T00:00:00Z");
Key keyInfo = new Key();
keyInfo.setDescription("Search patient records key");
keyInfo.setActions(new String[] {"search"});
keyInfo.setIndexes(new String[] {"patient_medical_records"});
keyInfo.setExpiresAt(dateParsed);
client.createKey(keyInfo);
security_guide_list_keys_1: |-
Client client = new Client(new Config("http://127.0.0.1:7700", "masterKey"));
client.getKeys();
security_guide_delete_key_1: |-
Client client = new Client(new Config("http://127.0.0.1:7700", "masterKey"));
client.deleteKey("d0552b41536279a0ad88bd595327b96f01176a60c2243e906c52ac02375f9bc4");
authorization_header_1: |-
Client client = new Client(new Config("http://127.0.0.1:7700", "masterKey"));
client.getKeys();
tenant_token_guide_generate_sdk_1: |-
Map<String, Object> filters = new HashMap<String, Object>();
filters.put("filter", "user_id = 1");
Map<String, Object> searchRules = new HashMap<String, Object>();
searchRules.put("patient_medical_records", filters);
Date expiresAt = new SimpleDateFormat("yyyy-MM-dd").parse("2025-12-20");
TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
TenantTokenOptions options = new TenantTokenOptions();
options.setApiKey("B5KdX2MY2jV6EXfUs6scSfmC...");
options.setExpiresAt(expiresAt);
String token = client.generateTenantToken(searchRules, options);
tenant_token_guide_search_sdk_1: |-
Client frontEndClient = new Client(new Config("http://localhost:7700", token));
frontEndClient.index("patient_medical_records").search("blood test");