chub-dev 0.1.0 → 0.1.2-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (139) hide show
  1. package/README.md +55 -0
  2. package/bin/chub-mcp +2 -0
  3. package/dist/airtable/docs/database/javascript/DOC.md +1437 -0
  4. package/dist/airtable/docs/database/python/DOC.md +1735 -0
  5. package/dist/amplitude/docs/analytics/javascript/DOC.md +1282 -0
  6. package/dist/amplitude/docs/analytics/python/DOC.md +1199 -0
  7. package/dist/anthropic/docs/claude-api/javascript/DOC.md +503 -0
  8. package/dist/anthropic/docs/claude-api/python/DOC.md +389 -0
  9. package/dist/asana/docs/tasks/DOC.md +1396 -0
  10. package/dist/assemblyai/docs/transcription/DOC.md +1043 -0
  11. package/dist/atlassian/docs/confluence/javascript/DOC.md +1347 -0
  12. package/dist/atlassian/docs/confluence/python/DOC.md +1604 -0
  13. package/dist/auth0/docs/identity/javascript/DOC.md +968 -0
  14. package/dist/auth0/docs/identity/python/DOC.md +1199 -0
  15. package/dist/aws/docs/s3/javascript/DOC.md +1773 -0
  16. package/dist/aws/docs/s3/python/DOC.md +1807 -0
  17. package/dist/binance/docs/trading/javascript/DOC.md +1315 -0
  18. package/dist/binance/docs/trading/python/DOC.md +1454 -0
  19. package/dist/braintree/docs/gateway/javascript/DOC.md +1278 -0
  20. package/dist/braintree/docs/gateway/python/DOC.md +1179 -0
  21. package/dist/chromadb/docs/embeddings-db/javascript/DOC.md +1263 -0
  22. package/dist/chromadb/docs/embeddings-db/python/DOC.md +1707 -0
  23. package/dist/clerk/docs/auth/javascript/DOC.md +1220 -0
  24. package/dist/clerk/docs/auth/python/DOC.md +274 -0
  25. package/dist/cloudflare/docs/workers/javascript/DOC.md +918 -0
  26. package/dist/cloudflare/docs/workers/python/DOC.md +994 -0
  27. package/dist/cockroachdb/docs/distributed-db/DOC.md +1500 -0
  28. package/dist/cohere/docs/llm/DOC.md +1335 -0
  29. package/dist/datadog/docs/monitoring/javascript/DOC.md +1740 -0
  30. package/dist/datadog/docs/monitoring/python/DOC.md +1815 -0
  31. package/dist/deepgram/docs/speech/javascript/DOC.md +885 -0
  32. package/dist/deepgram/docs/speech/python/DOC.md +685 -0
  33. package/dist/deepl/docs/translation/javascript/DOC.md +887 -0
  34. package/dist/deepl/docs/translation/python/DOC.md +944 -0
  35. package/dist/deepseek/docs/llm/DOC.md +1220 -0
  36. package/dist/directus/docs/headless-cms/javascript/DOC.md +1128 -0
  37. package/dist/directus/docs/headless-cms/python/DOC.md +1276 -0
  38. package/dist/discord/docs/bot/javascript/DOC.md +1090 -0
  39. package/dist/discord/docs/bot/python/DOC.md +1130 -0
  40. package/dist/elasticsearch/docs/search/DOC.md +1634 -0
  41. package/dist/elevenlabs/docs/text-to-speech/javascript/DOC.md +336 -0
  42. package/dist/elevenlabs/docs/text-to-speech/python/DOC.md +552 -0
  43. package/dist/firebase/docs/auth/DOC.md +1015 -0
  44. package/dist/gemini/docs/genai/javascript/DOC.md +691 -0
  45. package/dist/gemini/docs/genai/python/DOC.md +555 -0
  46. package/dist/github/docs/octokit/DOC.md +1560 -0
  47. package/dist/google/docs/bigquery/javascript/DOC.md +1688 -0
  48. package/dist/google/docs/bigquery/python/DOC.md +1503 -0
  49. package/dist/hubspot/docs/crm/javascript/DOC.md +1805 -0
  50. package/dist/hubspot/docs/crm/python/DOC.md +2033 -0
  51. package/dist/huggingface/docs/transformers/DOC.md +948 -0
  52. package/dist/intercom/docs/messaging/javascript/DOC.md +1844 -0
  53. package/dist/intercom/docs/messaging/python/DOC.md +1797 -0
  54. package/dist/jira/docs/issues/javascript/DOC.md +1420 -0
  55. package/dist/jira/docs/issues/python/DOC.md +1492 -0
  56. package/dist/kafka/docs/streaming/javascript/DOC.md +1671 -0
  57. package/dist/kafka/docs/streaming/python/DOC.md +1464 -0
  58. package/dist/landingai-ade/docs/api/DOC.md +620 -0
  59. package/dist/landingai-ade/docs/sdk/python/DOC.md +489 -0
  60. package/dist/landingai-ade/docs/sdk/typescript/DOC.md +542 -0
  61. package/dist/landingai-ade/skills/SKILL.md +489 -0
  62. package/dist/launchdarkly/docs/feature-flags/javascript/DOC.md +1191 -0
  63. package/dist/launchdarkly/docs/feature-flags/python/DOC.md +1671 -0
  64. package/dist/linear/docs/tracker/DOC.md +1554 -0
  65. package/dist/livekit/docs/realtime/javascript/DOC.md +303 -0
  66. package/dist/livekit/docs/realtime/python/DOC.md +163 -0
  67. package/dist/mailchimp/docs/marketing/DOC.md +1420 -0
  68. package/dist/meilisearch/docs/search/DOC.md +1241 -0
  69. package/dist/microsoft/docs/onedrive/javascript/DOC.md +1421 -0
  70. package/dist/microsoft/docs/onedrive/python/DOC.md +1549 -0
  71. package/dist/mongodb/docs/atlas/DOC.md +2041 -0
  72. package/dist/notion/docs/workspace-api/javascript/DOC.md +1435 -0
  73. package/dist/notion/docs/workspace-api/python/DOC.md +1400 -0
  74. package/dist/okta/docs/identity/javascript/DOC.md +1171 -0
  75. package/dist/okta/docs/identity/python/DOC.md +1401 -0
  76. package/dist/openai/docs/chat/javascript/DOC.md +407 -0
  77. package/dist/openai/docs/chat/python/DOC.md +568 -0
  78. package/dist/paypal/docs/checkout/DOC.md +278 -0
  79. package/dist/pinecone/docs/sdk/javascript/DOC.md +984 -0
  80. package/dist/pinecone/docs/sdk/python/DOC.md +1395 -0
  81. package/dist/plaid/docs/banking/javascript/DOC.md +1163 -0
  82. package/dist/plaid/docs/banking/python/DOC.md +1203 -0
  83. package/dist/playwright-community/skills/login-flows/SKILL.md +108 -0
  84. package/dist/postmark/docs/transactional-email/DOC.md +1168 -0
  85. package/dist/prisma/docs/orm/javascript/DOC.md +1419 -0
  86. package/dist/prisma/docs/orm/python/DOC.md +1317 -0
  87. package/dist/qdrant/docs/vector-search/javascript/DOC.md +1221 -0
  88. package/dist/qdrant/docs/vector-search/python/DOC.md +1653 -0
  89. package/dist/rabbitmq/docs/message-queue/javascript/DOC.md +1193 -0
  90. package/dist/rabbitmq/docs/message-queue/python/DOC.md +1243 -0
  91. package/dist/razorpay/docs/payments/javascript/DOC.md +1219 -0
  92. package/dist/razorpay/docs/payments/python/DOC.md +1330 -0
  93. package/dist/redis/docs/key-value/javascript/DOC.md +1851 -0
  94. package/dist/redis/docs/key-value/python/DOC.md +2054 -0
  95. package/dist/registry.json +2817 -0
  96. package/dist/replicate/docs/model-hosting/DOC.md +1318 -0
  97. package/dist/resend/docs/email/DOC.md +1271 -0
  98. package/dist/salesforce/docs/crm/javascript/DOC.md +1241 -0
  99. package/dist/salesforce/docs/crm/python/DOC.md +1183 -0
  100. package/dist/search-index.json +1 -0
  101. package/dist/sendgrid/docs/email-api/javascript/DOC.md +371 -0
  102. package/dist/sendgrid/docs/email-api/python/DOC.md +656 -0
  103. package/dist/sentry/docs/error-tracking/javascript/DOC.md +1073 -0
  104. package/dist/sentry/docs/error-tracking/python/DOC.md +1309 -0
  105. package/dist/shopify/docs/storefront/DOC.md +457 -0
  106. package/dist/slack/docs/workspace/javascript/DOC.md +933 -0
  107. package/dist/slack/docs/workspace/python/DOC.md +271 -0
  108. package/dist/square/docs/payments/javascript/DOC.md +1855 -0
  109. package/dist/square/docs/payments/python/DOC.md +1728 -0
  110. package/dist/stripe/docs/api/DOC.md +1727 -0
  111. package/dist/stripe/docs/payments/DOC.md +1726 -0
  112. package/dist/stytch/docs/auth/javascript/DOC.md +1813 -0
  113. package/dist/stytch/docs/auth/python/DOC.md +1962 -0
  114. package/dist/supabase/docs/client/DOC.md +1606 -0
  115. package/dist/twilio/docs/messaging/python/DOC.md +469 -0
  116. package/dist/twilio/docs/messaging/typescript/DOC.md +946 -0
  117. package/dist/vercel/docs/platform/DOC.md +1940 -0
  118. package/dist/weaviate/docs/vector-db/javascript/DOC.md +1268 -0
  119. package/dist/weaviate/docs/vector-db/python/DOC.md +1388 -0
  120. package/dist/zendesk/docs/support/javascript/DOC.md +2150 -0
  121. package/dist/zendesk/docs/support/python/DOC.md +2297 -0
  122. package/package.json +22 -6
  123. package/skills/get-api-docs/SKILL.md +84 -0
  124. package/src/commands/annotate.js +83 -0
  125. package/src/commands/build.js +12 -1
  126. package/src/commands/feedback.js +150 -0
  127. package/src/commands/get.js +83 -42
  128. package/src/commands/search.js +7 -0
  129. package/src/index.js +43 -17
  130. package/src/lib/analytics.js +90 -0
  131. package/src/lib/annotations.js +57 -0
  132. package/src/lib/bm25.js +170 -0
  133. package/src/lib/cache.js +69 -6
  134. package/src/lib/config.js +8 -3
  135. package/src/lib/identity.js +99 -0
  136. package/src/lib/registry.js +103 -20
  137. package/src/lib/telemetry.js +86 -0
  138. package/src/mcp/server.js +177 -0
  139. package/src/mcp/tools.js +251 -0
@@ -0,0 +1,1634 @@
1
+ ---
2
+ name: search
3
+ description: "Official Elasticsearch JavaScript client for full-text search, indexing, and vector search operations."
4
+ metadata:
5
+ languages: "javascript"
6
+ versions: "9.2.0"
7
+ updated-on: "2026-03-01"
8
+ source: maintainer
9
+ tags: "elasticsearch,search,full-text,indexing,vector"
10
+ ---
11
+
12
+ # Elasticsearch JavaScript Client Coding Guidelines
13
+
14
+ You are an Elasticsearch API coding expert. Help me with writing code using the Elasticsearch JavaScript client, calling the official libraries and SDKs.
15
+
16
+ ## Golden Rule: Use the Correct and Current SDK
17
+
18
+ Always use the official Elasticsearch JavaScript client for all Elasticsearch interactions.
19
+
20
+ - **Library Name:** Elasticsearch JavaScript Client
21
+ - **NPM Package:** `@elastic/elasticsearch`
22
+ - **Current Version:** 9.2.0
23
+
24
+ **Installation:**
25
+
26
+ ```bash
27
+ npm install @elastic/elasticsearch
28
+ ```
29
+
30
+ **Import Patterns:**
31
+
32
+ ```javascript
33
+ // ES6 import
34
+ import { Client } from '@elastic/elasticsearch';
35
+
36
+ // CommonJS require
37
+ const { Client } = require('@elastic/elasticsearch');
38
+ ```
39
+
40
+ Do not use legacy or unofficial packages. The `@elastic/elasticsearch` package is the only official client.
41
+
42
+ ## Initialization and Authentication
43
+
44
+ The Elasticsearch client requires creating a `Client` instance for all API calls.
45
+
46
+ ### Basic Initialization with API Key
47
+
48
+ ```javascript
49
+ import { Client } from '@elastic/elasticsearch';
50
+
51
+ const client = new Client({
52
+ node: 'https://localhost:9200',
53
+ auth: {
54
+ apiKey: 'base64EncodedApiKey'
55
+ }
56
+ });
57
+ ```
58
+
59
+ ### API Key with ID and Secret
60
+
61
+ ```javascript
62
+ import { Client } from '@elastic/elasticsearch';
63
+
64
+ const client = new Client({
65
+ node: 'https://localhost:9200',
66
+ auth: {
67
+ apiKey: {
68
+ id: 'your-api-key-id',
69
+ api_key: 'your-api-key-secret'
70
+ }
71
+ }
72
+ });
73
+ ```
74
+
75
+ ### Basic Authentication
76
+
77
+ ```javascript
78
+ import { Client } from '@elastic/elasticsearch';
79
+
80
+ const client = new Client({
81
+ node: 'https://localhost:9200',
82
+ auth: {
83
+ username: 'elastic',
84
+ password: 'changeme'
85
+ }
86
+ });
87
+ ```
88
+
89
+ ### Bearer Token Authentication
90
+
91
+ ```javascript
92
+ import { Client } from '@elastic/elasticsearch';
93
+
94
+ const client = new Client({
95
+ node: 'https://localhost:9200',
96
+ auth: {
97
+ bearer: 'your-bearer-token'
98
+ }
99
+ });
100
+ ```
101
+
102
+ ### Elastic Cloud Authentication
103
+
104
+ ```javascript
105
+ import { Client } from '@elastic/elasticsearch';
106
+
107
+ const client = new Client({
108
+ cloud: {
109
+ id: 'your-cloud-id'
110
+ },
111
+ auth: {
112
+ username: 'elastic',
113
+ password: 'your-password'
114
+ }
115
+ });
116
+ ```
117
+
118
+ ### SSL/TLS Configuration
119
+
120
+ ```javascript
121
+ import { Client } from '@elastic/elasticsearch';
122
+ import fs from 'fs';
123
+
124
+ const client = new Client({
125
+ node: 'https://localhost:9200',
126
+ auth: {
127
+ username: 'elastic',
128
+ password: 'changeme'
129
+ },
130
+ tls: {
131
+ ca: fs.readFileSync('./http_ca.crt'),
132
+ rejectUnauthorized: true
133
+ }
134
+ });
135
+ ```
136
+
137
+ ### CA Certificate Fingerprint
138
+
139
+ ```javascript
140
+ import { Client } from '@elastic/elasticsearch';
141
+
142
+ const client = new Client({
143
+ node: 'https://localhost:9200',
144
+ auth: {
145
+ username: 'elastic',
146
+ password: 'changeme'
147
+ },
148
+ caFingerprint: '20:0D:CA:FA:76:...'
149
+ });
150
+ ```
151
+
152
+ ### Multiple Certificates
153
+
154
+ ```javascript
155
+ import { Client } from '@elastic/elasticsearch';
156
+ import fs from 'fs';
157
+
158
+ const client = new Client({
159
+ node: 'https://localhost:9200',
160
+ tls: {
161
+ ca: [
162
+ fs.readFileSync('./ca.pem'),
163
+ fs.readFileSync('./intermediateRoot.pem')
164
+ ],
165
+ rejectUnauthorized: true
166
+ }
167
+ });
168
+ ```
169
+
170
+ ## Document Operations
171
+
172
+ ### Index a Document (Create/Update)
173
+
174
+ ```javascript
175
+ // Index with auto-generated ID
176
+ const result = await client.index({
177
+ index: 'products',
178
+ document: {
179
+ name: 'Laptop',
180
+ price: 999.99,
181
+ category: 'electronics'
182
+ }
183
+ });
184
+
185
+ console.log(result._id); // Auto-generated ID
186
+ ```
187
+
188
+ ### Index with Specific ID
189
+
190
+ ```javascript
191
+ const result = await client.index({
192
+ index: 'products',
193
+ id: 'product-123',
194
+ document: {
195
+ name: 'Laptop',
196
+ price: 999.99,
197
+ category: 'electronics'
198
+ }
199
+ });
200
+
201
+ console.log(result.result); // 'created' or 'updated'
202
+ ```
203
+
204
+ ### Index with Refresh
205
+
206
+ ```javascript
207
+ const result = await client.index({
208
+ index: 'products',
209
+ id: 'product-123',
210
+ refresh: 'wait_for', // Options: true, false, 'wait_for'
211
+ document: {
212
+ name: 'Laptop',
213
+ price: 999.99,
214
+ category: 'electronics'
215
+ }
216
+ });
217
+ ```
218
+
219
+ ### Get a Document
220
+
221
+ ```javascript
222
+ const result = await client.get({
223
+ index: 'products',
224
+ id: 'product-123'
225
+ });
226
+
227
+ console.log(result._source);
228
+ ```
229
+
230
+ ### Update a Document
231
+
232
+ ```javascript
233
+ const result = await client.update({
234
+ index: 'products',
235
+ id: 'product-123',
236
+ doc: {
237
+ price: 899.99,
238
+ on_sale: true
239
+ }
240
+ });
241
+
242
+ console.log(result.result); // 'updated'
243
+ ```
244
+
245
+ ### Update with Script
246
+
247
+ ```javascript
248
+ const result = await client.update({
249
+ index: 'products',
250
+ id: 'product-123',
251
+ script: {
252
+ source: 'ctx._source.price -= params.discount',
253
+ lang: 'painless',
254
+ params: {
255
+ discount: 100
256
+ }
257
+ }
258
+ });
259
+ ```
260
+
261
+ ### Delete a Document
262
+
263
+ ```javascript
264
+ const result = await client.delete({
265
+ index: 'products',
266
+ id: 'product-123'
267
+ });
268
+
269
+ console.log(result.result); // 'deleted'
270
+ ```
271
+
272
+ ### Check if Document Exists
273
+
274
+ ```javascript
275
+ const exists = await client.exists({
276
+ index: 'products',
277
+ id: 'product-123'
278
+ });
279
+
280
+ console.log(exists); // true or false
281
+ ```
282
+
283
+ ## Bulk Operations
284
+
285
+ ### Bulk Index
286
+
287
+ ```javascript
288
+ const operations = [];
289
+
290
+ const documents = [
291
+ { name: 'Product 1', price: 10 },
292
+ { name: 'Product 2', price: 20 },
293
+ { name: 'Product 3', price: 30 }
294
+ ];
295
+
296
+ documents.forEach(doc => {
297
+ operations.push({ index: { _index: 'products' } });
298
+ operations.push(doc);
299
+ });
300
+
301
+ const result = await client.bulk({
302
+ operations: operations
303
+ });
304
+
305
+ // Check for errors
306
+ if (result.errors) {
307
+ const erroredDocuments = [];
308
+ result.items.forEach((item, i) => {
309
+ if (item.index?.error) {
310
+ erroredDocuments.push({
311
+ status: item.index.status,
312
+ error: item.index.error,
313
+ document: documents[i]
314
+ });
315
+ }
316
+ });
317
+ console.log('Errors:', erroredDocuments);
318
+ }
319
+ ```
320
+
321
+ ### Bulk with Multiple Operations
322
+
323
+ ```javascript
324
+ const operations = [
325
+ // Index operation
326
+ { index: { _index: 'products', _id: '1' } },
327
+ { name: 'Product 1', price: 10 },
328
+
329
+ // Update operation
330
+ { update: { _index: 'products', _id: '2' } },
331
+ { doc: { price: 25 } },
332
+
333
+ // Delete operation
334
+ { delete: { _index: 'products', _id: '3' } }
335
+ ];
336
+
337
+ const result = await client.bulk({ operations });
338
+ ```
339
+
340
+ ### Bulk Helper
341
+
342
+ ```javascript
343
+ import { Client } from '@elastic/elasticsearch';
344
+
345
+ const client = new Client({ node: 'https://localhost:9200' });
346
+
347
+ const documents = [
348
+ { name: 'Product 1', price: 10 },
349
+ { name: 'Product 2', price: 20 },
350
+ { name: 'Product 3', price: 30 }
351
+ ];
352
+
353
+ const result = await client.helpers.bulk({
354
+ datasource: documents,
355
+ onDocument(doc) {
356
+ return {
357
+ index: { _index: 'products' }
358
+ };
359
+ }
360
+ });
361
+
362
+ console.log(result);
363
+ ```
364
+
365
+ ### Bulk Helper with Generator
366
+
367
+ ```javascript
368
+ async function* generator() {
369
+ for (let i = 0; i < 1000; i++) {
370
+ yield { name: `Product ${i}`, price: i * 10 };
371
+ }
372
+ }
373
+
374
+ const result = await client.helpers.bulk({
375
+ datasource: generator(),
376
+ onDocument(doc) {
377
+ return {
378
+ index: { _index: 'products' }
379
+ };
380
+ }
381
+ });
382
+ ```
383
+
384
+ ## Search Operations
385
+
386
+ ### Basic Search
387
+
388
+ ```javascript
389
+ const result = await client.search({
390
+ index: 'products',
391
+ query: {
392
+ match_all: {}
393
+ }
394
+ });
395
+
396
+ result.hits.hits.forEach(hit => {
397
+ console.log(hit._source);
398
+ });
399
+ ```
400
+
401
+ ### Match Query
402
+
403
+ ```javascript
404
+ const result = await client.search({
405
+ index: 'products',
406
+ query: {
407
+ match: {
408
+ name: 'laptop'
409
+ }
410
+ }
411
+ });
412
+ ```
413
+
414
+ ### Match with Options
415
+
416
+ ```javascript
417
+ const result = await client.search({
418
+ index: 'products',
419
+ query: {
420
+ match: {
421
+ description: {
422
+ query: 'gaming laptop',
423
+ operator: 'and',
424
+ fuzziness: 'AUTO'
425
+ }
426
+ }
427
+ }
428
+ });
429
+ ```
430
+
431
+ ### Match Phrase Query
432
+
433
+ ```javascript
434
+ const result = await client.search({
435
+ index: 'products',
436
+ query: {
437
+ match_phrase: {
438
+ description: 'high performance laptop'
439
+ }
440
+ }
441
+ });
442
+ ```
443
+
444
+ ### Term Query (Exact Match)
445
+
446
+ ```javascript
447
+ const result = await client.search({
448
+ index: 'products',
449
+ query: {
450
+ term: {
451
+ 'category.keyword': 'electronics'
452
+ }
453
+ }
454
+ });
455
+ ```
456
+
457
+ ### Terms Query (Multiple Values)
458
+
459
+ ```javascript
460
+ const result = await client.search({
461
+ index: 'products',
462
+ query: {
463
+ terms: {
464
+ 'category.keyword': ['electronics', 'computers', 'accessories']
465
+ }
466
+ }
467
+ });
468
+ ```
469
+
470
+ ### Range Query
471
+
472
+ ```javascript
473
+ const result = await client.search({
474
+ index: 'products',
475
+ query: {
476
+ range: {
477
+ price: {
478
+ gte: 100,
479
+ lte: 1000
480
+ }
481
+ }
482
+ }
483
+ });
484
+ ```
485
+
486
+ ### Range Query with Dates
487
+
488
+ ```javascript
489
+ const result = await client.search({
490
+ index: 'products',
491
+ query: {
492
+ range: {
493
+ created_at: {
494
+ gte: '2024-01-01',
495
+ lte: 'now'
496
+ }
497
+ }
498
+ }
499
+ });
500
+ ```
501
+
502
+ ### Boolean Query
503
+
504
+ ```javascript
505
+ const result = await client.search({
506
+ index: 'products',
507
+ query: {
508
+ bool: {
509
+ must: [
510
+ { match: { name: 'laptop' } }
511
+ ],
512
+ filter: [
513
+ { term: { 'category.keyword': 'electronics' } },
514
+ { range: { price: { lte: 1000 } } }
515
+ ],
516
+ should: [
517
+ { term: { on_sale: true } }
518
+ ],
519
+ must_not: [
520
+ { term: { discontinued: true } }
521
+ ],
522
+ minimum_should_match: 0
523
+ }
524
+ }
525
+ });
526
+ ```
527
+
528
+ ### Search with Pagination
529
+
530
+ ```javascript
531
+ const result = await client.search({
532
+ index: 'products',
533
+ from: 0,
534
+ size: 20,
535
+ query: {
536
+ match_all: {}
537
+ }
538
+ });
539
+ ```
540
+
541
+ ### Search with Sorting
542
+
543
+ ```javascript
544
+ const result = await client.search({
545
+ index: 'products',
546
+ query: {
547
+ match_all: {}
548
+ },
549
+ sort: [
550
+ { price: { order: 'desc' } },
551
+ { created_at: { order: 'desc' } }
552
+ ]
553
+ });
554
+ ```
555
+
556
+ ### Search with Source Filtering
557
+
558
+ ```javascript
559
+ const result = await client.search({
560
+ index: 'products',
561
+ query: {
562
+ match_all: {}
563
+ },
564
+ _source: ['name', 'price', 'category']
565
+ });
566
+ ```
567
+
568
+ ### Multi-Match Query
569
+
570
+ ```javascript
571
+ const result = await client.search({
572
+ index: 'products',
573
+ query: {
574
+ multi_match: {
575
+ query: 'laptop',
576
+ fields: ['name^2', 'description', 'category']
577
+ }
578
+ }
579
+ });
580
+ ```
581
+
582
+ ### Wildcard Query
583
+
584
+ ```javascript
585
+ const result = await client.search({
586
+ index: 'products',
587
+ query: {
588
+ wildcard: {
589
+ 'name.keyword': 'lap*'
590
+ }
591
+ }
592
+ });
593
+ ```
594
+
595
+ ### Prefix Query
596
+
597
+ ```javascript
598
+ const result = await client.search({
599
+ index: 'products',
600
+ query: {
601
+ prefix: {
602
+ 'name.keyword': 'lap'
603
+ }
604
+ }
605
+ });
606
+ ```
607
+
608
+ ### Exists Query
609
+
610
+ ```javascript
611
+ const result = await client.search({
612
+ index: 'products',
613
+ query: {
614
+ exists: {
615
+ field: 'discount'
616
+ }
617
+ }
618
+ });
619
+ ```
620
+
621
+ ## Aggregations
622
+
623
+ ### Terms Aggregation
624
+
625
+ ```javascript
626
+ const result = await client.search({
627
+ index: 'products',
628
+ size: 0,
629
+ query: {
630
+ match_all: {}
631
+ },
632
+ aggs: {
633
+ categories: {
634
+ terms: {
635
+ field: 'category.keyword',
636
+ size: 10
637
+ }
638
+ }
639
+ }
640
+ });
641
+
642
+ result.aggregations.categories.buckets.forEach(bucket => {
643
+ console.log(`${bucket.key}: ${bucket.doc_count}`);
644
+ });
645
+ ```
646
+
647
+ ### Terms Aggregation with Size
648
+
649
+ ```javascript
650
+ const result = await client.search({
651
+ index: 'products',
652
+ size: 0,
653
+ aggs: {
654
+ top_categories: {
655
+ terms: {
656
+ field: 'category.keyword',
657
+ size: 20,
658
+ order: { _count: 'desc' }
659
+ }
660
+ }
661
+ }
662
+ });
663
+ ```
664
+
665
+ ### Metric Aggregations
666
+
667
+ ```javascript
668
+ const result = await client.search({
669
+ index: 'products',
670
+ size: 0,
671
+ aggs: {
672
+ avg_price: {
673
+ avg: { field: 'price' }
674
+ },
675
+ min_price: {
676
+ min: { field: 'price' }
677
+ },
678
+ max_price: {
679
+ max: { field: 'price' }
680
+ },
681
+ sum_price: {
682
+ sum: { field: 'price' }
683
+ }
684
+ }
685
+ });
686
+
687
+ console.log('Average:', result.aggregations.avg_price.value);
688
+ console.log('Min:', result.aggregations.min_price.value);
689
+ console.log('Max:', result.aggregations.max_price.value);
690
+ console.log('Sum:', result.aggregations.sum_price.value);
691
+ ```
692
+
693
+ ### Stats Aggregation
694
+
695
+ ```javascript
696
+ const result = await client.search({
697
+ index: 'products',
698
+ size: 0,
699
+ aggs: {
700
+ price_stats: {
701
+ stats: { field: 'price' }
702
+ }
703
+ }
704
+ });
705
+
706
+ console.log(result.aggregations.price_stats);
707
+ // Returns: count, min, max, avg, sum
708
+ ```
709
+
710
+ ### Nested Aggregations
711
+
712
+ ```javascript
713
+ const result = await client.search({
714
+ index: 'products',
715
+ size: 0,
716
+ aggs: {
717
+ categories: {
718
+ terms: {
719
+ field: 'category.keyword'
720
+ },
721
+ aggs: {
722
+ avg_price: {
723
+ avg: { field: 'price' }
724
+ }
725
+ }
726
+ }
727
+ }
728
+ });
729
+
730
+ result.aggregations.categories.buckets.forEach(bucket => {
731
+ console.log(`${bucket.key}: ${bucket.avg_price.value}`);
732
+ });
733
+ ```
734
+
735
+ ### Date Histogram Aggregation
736
+
737
+ ```javascript
738
+ const result = await client.search({
739
+ index: 'products',
740
+ size: 0,
741
+ aggs: {
742
+ sales_over_time: {
743
+ date_histogram: {
744
+ field: 'created_at',
745
+ calendar_interval: 'month'
746
+ }
747
+ }
748
+ }
749
+ });
750
+ ```
751
+
752
+ ### Date Histogram with Metrics
753
+
754
+ ```javascript
755
+ const result = await client.search({
756
+ index: 'products',
757
+ size: 0,
758
+ aggs: {
759
+ sales_per_month: {
760
+ date_histogram: {
761
+ field: 'created_at',
762
+ calendar_interval: 'month'
763
+ },
764
+ aggs: {
765
+ total_sales: {
766
+ sum: { field: 'price' }
767
+ },
768
+ avg_price: {
769
+ avg: { field: 'price' }
770
+ }
771
+ }
772
+ }
773
+ }
774
+ });
775
+ ```
776
+
777
+ ### Range Aggregation
778
+
779
+ ```javascript
780
+ const result = await client.search({
781
+ index: 'products',
782
+ size: 0,
783
+ aggs: {
784
+ price_ranges: {
785
+ range: {
786
+ field: 'price',
787
+ ranges: [
788
+ { to: 50 },
789
+ { from: 50, to: 100 },
790
+ { from: 100, to: 500 },
791
+ { from: 500 }
792
+ ]
793
+ }
794
+ }
795
+ }
796
+ });
797
+ ```
798
+
799
+ ### Histogram Aggregation
800
+
801
+ ```javascript
802
+ const result = await client.search({
803
+ index: 'products',
804
+ size: 0,
805
+ aggs: {
806
+ price_histogram: {
807
+ histogram: {
808
+ field: 'price',
809
+ interval: 100
810
+ }
811
+ }
812
+ }
813
+ });
814
+ ```
815
+
816
+ ### Filter Aggregation
817
+
818
+ ```javascript
819
+ const result = await client.search({
820
+ index: 'products',
821
+ size: 0,
822
+ aggs: {
823
+ electronics: {
824
+ filter: {
825
+ term: { 'category.keyword': 'electronics' }
826
+ },
827
+ aggs: {
828
+ avg_price: {
829
+ avg: { field: 'price' }
830
+ }
831
+ }
832
+ }
833
+ }
834
+ });
835
+ ```
836
+
837
+ ### Cardinality Aggregation
838
+
839
+ ```javascript
840
+ const result = await client.search({
841
+ index: 'products',
842
+ size: 0,
843
+ aggs: {
844
+ unique_categories: {
845
+ cardinality: {
846
+ field: 'category.keyword'
847
+ }
848
+ }
849
+ }
850
+ });
851
+
852
+ console.log('Unique categories:', result.aggregations.unique_categories.value);
853
+ ```
854
+
855
+ ## Advanced Search Operations
856
+
857
+ ### Multi-Search (msearch)
858
+
859
+ ```javascript
860
+ const searches = [
861
+ { index: 'products' },
862
+ { query: { match: { category: 'electronics' } } },
863
+
864
+ { index: 'products' },
865
+ { query: { match: { category: 'books' } } }
866
+ ];
867
+
868
+ const result = await client.msearch({
869
+ searches: searches
870
+ });
871
+
872
+ result.responses.forEach((response, i) => {
873
+ console.log(`Search ${i}:`, response.hits.total.value);
874
+ });
875
+ ```
876
+
877
+ ### Scroll API for Large Result Sets
878
+
879
+ ```javascript
880
+ // Initial search with scroll
881
+ let result = await client.search({
882
+ index: 'products',
883
+ scroll: '1m',
884
+ size: 100,
885
+ query: {
886
+ match_all: {}
887
+ }
888
+ });
889
+
890
+ let scrollId = result._scroll_id;
891
+ let hits = result.hits.hits;
892
+
893
+ console.log(`Retrieved ${hits.length} documents`);
894
+
895
+ // Continue scrolling
896
+ while (hits.length > 0) {
897
+ result = await client.scroll({
898
+ scroll_id: scrollId,
899
+ scroll: '1m'
900
+ });
901
+
902
+ scrollId = result._scroll_id;
903
+ hits = result.hits.hits;
904
+
905
+ console.log(`Retrieved ${hits.length} more documents`);
906
+ }
907
+
908
+ // Clear scroll
909
+ await client.clearScroll({
910
+ scroll_id: scrollId
911
+ });
912
+ ```
913
+
914
+ ### Count API
915
+
916
+ ```javascript
917
+ const result = await client.count({
918
+ index: 'products',
919
+ query: {
920
+ match: {
921
+ category: 'electronics'
922
+ }
923
+ }
924
+ });
925
+
926
+ console.log('Total documents:', result.count);
927
+ ```
928
+
929
+ ### Update By Query
930
+
931
+ ```javascript
932
+ const result = await client.updateByQuery({
933
+ index: 'products',
934
+ query: {
935
+ match: {
936
+ category: 'electronics'
937
+ }
938
+ },
939
+ script: {
940
+ source: 'ctx._source.price = ctx._source.price * 0.9',
941
+ lang: 'painless'
942
+ }
943
+ });
944
+
945
+ console.log('Updated:', result.updated);
946
+ ```
947
+
948
+ ### Update By Query with Parameters
949
+
950
+ ```javascript
951
+ const result = await client.updateByQuery({
952
+ index: 'products',
953
+ query: {
954
+ term: { on_sale: false }
955
+ },
956
+ script: {
957
+ source: 'ctx._source.price -= params.discount',
958
+ lang: 'painless',
959
+ params: {
960
+ discount: 50
961
+ }
962
+ }
963
+ });
964
+ ```
965
+
966
+ ### Delete By Query
967
+
968
+ ```javascript
969
+ const result = await client.deleteByQuery({
970
+ index: 'products',
971
+ query: {
972
+ term: {
973
+ discontinued: true
974
+ }
975
+ }
976
+ });
977
+
978
+ console.log('Deleted:', result.deleted);
979
+ ```
980
+
981
+ ### Delete By Query with Conflicts
982
+
983
+ ```javascript
984
+ const result = await client.deleteByQuery({
985
+ index: 'products',
986
+ conflicts: 'proceed',
987
+ query: {
988
+ range: {
989
+ created_at: {
990
+ lt: 'now-1y'
991
+ }
992
+ }
993
+ }
994
+ });
995
+ ```
996
+
997
+ ### Reindex
998
+
999
+ ```javascript
1000
+ const result = await client.reindex({
1001
+ source: {
1002
+ index: 'products'
1003
+ },
1004
+ dest: {
1005
+ index: 'products_v2'
1006
+ }
1007
+ });
1008
+
1009
+ console.log('Reindexed:', result.total);
1010
+ ```
1011
+
1012
+ ### Reindex with Query
1013
+
1014
+ ```javascript
1015
+ const result = await client.reindex({
1016
+ source: {
1017
+ index: 'products',
1018
+ query: {
1019
+ term: { category: 'electronics' }
1020
+ }
1021
+ },
1022
+ dest: {
1023
+ index: 'electronics_products'
1024
+ }
1025
+ });
1026
+ ```
1027
+
1028
+ ## Index Management
1029
+
1030
+ ### Create Index
1031
+
1032
+ ```javascript
1033
+ const result = await client.indices.create({
1034
+ index: 'products'
1035
+ });
1036
+ ```
1037
+
1038
+ ### Create Index with Settings
1039
+
1040
+ ```javascript
1041
+ const result = await client.indices.create({
1042
+ index: 'products',
1043
+ settings: {
1044
+ number_of_shards: 3,
1045
+ number_of_replicas: 2
1046
+ }
1047
+ });
1048
+ ```
1049
+
1050
+ ### Create Index with Mappings
1051
+
1052
+ ```javascript
1053
+ const result = await client.indices.create({
1054
+ index: 'products',
1055
+ mappings: {
1056
+ properties: {
1057
+ name: { type: 'text' },
1058
+ description: { type: 'text' },
1059
+ price: { type: 'float' },
1060
+ category: {
1061
+ type: 'text',
1062
+ fields: {
1063
+ keyword: { type: 'keyword' }
1064
+ }
1065
+ },
1066
+ created_at: { type: 'date' },
1067
+ tags: { type: 'keyword' },
1068
+ in_stock: { type: 'boolean' }
1069
+ }
1070
+ }
1071
+ });
1072
+ ```
1073
+
1074
+ ### Create Index with Settings and Mappings
1075
+
1076
+ ```javascript
1077
+ const result = await client.indices.create({
1078
+ index: 'products',
1079
+ settings: {
1080
+ number_of_shards: 3,
1081
+ number_of_replicas: 2,
1082
+ analysis: {
1083
+ analyzer: {
1084
+ custom_analyzer: {
1085
+ type: 'custom',
1086
+ tokenizer: 'standard',
1087
+ filter: ['lowercase', 'asciifolding']
1088
+ }
1089
+ }
1090
+ }
1091
+ },
1092
+ mappings: {
1093
+ properties: {
1094
+ name: {
1095
+ type: 'text',
1096
+ analyzer: 'custom_analyzer'
1097
+ },
1098
+ price: { type: 'float' },
1099
+ category: { type: 'keyword' }
1100
+ }
1101
+ }
1102
+ });
1103
+ ```
1104
+
1105
+ ### Delete Index
1106
+
1107
+ ```javascript
1108
+ const result = await client.indices.delete({
1109
+ index: 'products'
1110
+ });
1111
+ ```
1112
+
1113
+ ### Check if Index Exists
1114
+
1115
+ ```javascript
1116
+ const exists = await client.indices.exists({
1117
+ index: 'products'
1118
+ });
1119
+
1120
+ console.log(exists); // true or false
1121
+ ```
1122
+
1123
+ ### Get Index
1124
+
1125
+ ```javascript
1126
+ const result = await client.indices.get({
1127
+ index: 'products'
1128
+ });
1129
+
1130
+ console.log(result.products);
1131
+ ```
1132
+
1133
+ ### Get Index Mapping
1134
+
1135
+ ```javascript
1136
+ const result = await client.indices.getMapping({
1137
+ index: 'products'
1138
+ });
1139
+
1140
+ console.log(result.products.mappings);
1141
+ ```
1142
+
1143
+ ### Update Index Mapping
1144
+
1145
+ ```javascript
1146
+ const result = await client.indices.putMapping({
1147
+ index: 'products',
1148
+ properties: {
1149
+ new_field: { type: 'text' }
1150
+ }
1151
+ });
1152
+ ```
1153
+
1154
+ ### Get Index Settings
1155
+
1156
+ ```javascript
1157
+ const result = await client.indices.getSettings({
1158
+ index: 'products'
1159
+ });
1160
+
1161
+ console.log(result.products.settings);
1162
+ ```
1163
+
1164
+ ### Update Index Settings
1165
+
1166
+ ```javascript
1167
+ // Close index first
1168
+ await client.indices.close({ index: 'products' });
1169
+
1170
+ // Update settings
1171
+ await client.indices.putSettings({
1172
+ index: 'products',
1173
+ settings: {
1174
+ number_of_replicas: 3
1175
+ }
1176
+ });
1177
+
1178
+ // Reopen index
1179
+ await client.indices.open({ index: 'products' });
1180
+ ```
1181
+
1182
+ ### Refresh Index
1183
+
1184
+ ```javascript
1185
+ const result = await client.indices.refresh({
1186
+ index: 'products'
1187
+ });
1188
+ ```
1189
+
1190
+ ### Flush Index
1191
+
1192
+ ```javascript
1193
+ const result = await client.indices.flush({
1194
+ index: 'products'
1195
+ });
1196
+ ```
1197
+
1198
+ ### Index Aliases
1199
+
1200
+ ```javascript
1201
+ // Add alias
1202
+ await client.indices.putAlias({
1203
+ index: 'products_v1',
1204
+ name: 'products'
1205
+ });
1206
+
1207
+ // Get aliases
1208
+ const aliases = await client.indices.getAlias({
1209
+ index: 'products_v1'
1210
+ });
1211
+
1212
+ // Delete alias
1213
+ await client.indices.deleteAlias({
1214
+ index: 'products_v1',
1215
+ name: 'products'
1216
+ });
1217
+ ```
1218
+
1219
+ ### Update Aliases (Atomic)
1220
+
1221
+ ```javascript
1222
+ const result = await client.indices.updateAliases({
1223
+ actions: [
1224
+ {
1225
+ remove: { index: 'products_v1', alias: 'products' }
1226
+ },
1227
+ {
1228
+ add: { index: 'products_v2', alias: 'products' }
1229
+ }
1230
+ ]
1231
+ });
1232
+ ```
1233
+
1234
+ ### Index Statistics
1235
+
1236
+ ```javascript
1237
+ const result = await client.indices.stats({
1238
+ index: 'products'
1239
+ });
1240
+
1241
+ console.log(result._all.total);
1242
+ ```
1243
+
1244
+ ## Error Handling
1245
+
1246
+ ### Basic Error Handling
1247
+
1248
+ ```javascript
1249
+ try {
1250
+ const result = await client.search({
1251
+ index: 'products',
1252
+ query: {
1253
+ match: { name: 'laptop' }
1254
+ }
1255
+ });
1256
+ console.log(result.hits.hits);
1257
+ } catch (error) {
1258
+ console.error('Error:', error.message);
1259
+ console.error('Status:', error.meta?.statusCode);
1260
+ }
1261
+ ```
1262
+
1263
+ ### Handling Specific Errors
1264
+
1265
+ ```javascript
1266
+ import { errors } from '@elastic/elasticsearch';
1267
+
1268
+ try {
1269
+ const result = await client.get({
1270
+ index: 'products',
1271
+ id: 'missing-id'
1272
+ });
1273
+ } catch (error) {
1274
+ if (error instanceof errors.ResponseError) {
1275
+ if (error.meta.statusCode === 404) {
1276
+ console.log('Document not found');
1277
+ } else {
1278
+ console.error('Response error:', error.message);
1279
+ }
1280
+ } else if (error instanceof errors.TimeoutError) {
1281
+ console.error('Request timeout');
1282
+ } else if (error instanceof errors.ConnectionError) {
1283
+ console.error('Connection error');
1284
+ } else {
1285
+ console.error('Unknown error:', error);
1286
+ }
1287
+ }
1288
+ ```
1289
+
1290
+ ### Bulk Error Handling
1291
+
1292
+ ```javascript
1293
+ const operations = [
1294
+ { index: { _index: 'products', _id: '1' } },
1295
+ { name: 'Product 1', price: 10 },
1296
+ { index: { _index: 'products', _id: '2' } },
1297
+ { name: 'Product 2', price: 20 }
1298
+ ];
1299
+
1300
+ const result = await client.bulk({ operations });
1301
+
1302
+ if (result.errors) {
1303
+ const erroredDocuments = [];
1304
+
1305
+ result.items.forEach((item, i) => {
1306
+ const operation = Object.keys(item)[0];
1307
+ if (item[operation].error) {
1308
+ erroredDocuments.push({
1309
+ status: item[operation].status,
1310
+ error: item[operation].error,
1311
+ operation: operations[i * 2],
1312
+ document: operations[i * 2 + 1]
1313
+ });
1314
+ }
1315
+ });
1316
+
1317
+ console.error('Failed documents:', erroredDocuments);
1318
+ } else {
1319
+ console.log('All documents indexed successfully');
1320
+ }
1321
+ ```
1322
+
1323
+ ## Client Configuration
1324
+
1325
+ ### Connection Pool Configuration
1326
+
1327
+ ```javascript
1328
+ import { Client } from '@elastic/elasticsearch';
1329
+
1330
+ const client = new Client({
1331
+ node: 'https://localhost:9200',
1332
+ maxRetries: 5,
1333
+ requestTimeout: 60000,
1334
+ sniffOnStart: true
1335
+ });
1336
+ ```
1337
+
1338
+ ### Multiple Nodes
1339
+
1340
+ ```javascript
1341
+ import { Client } from '@elastic/elasticsearch';
1342
+
1343
+ const client = new Client({
1344
+ nodes: [
1345
+ 'https://node1.example.com:9200',
1346
+ 'https://node2.example.com:9200',
1347
+ 'https://node3.example.com:9200'
1348
+ ]
1349
+ });
1350
+ ```
1351
+
1352
+ ### Custom Headers
1353
+
1354
+ ```javascript
1355
+ import { Client } from '@elastic/elasticsearch';
1356
+
1357
+ const client = new Client({
1358
+ node: 'https://localhost:9200',
1359
+ headers: {
1360
+ 'X-Custom-Header': 'custom-value'
1361
+ }
1362
+ });
1363
+ ```
1364
+
1365
+ ### Proxy Configuration
1366
+
1367
+ ```javascript
1368
+ import { Client } from '@elastic/elasticsearch';
1369
+ import { HttpProxyAgent } from 'http-proxy-agent';
1370
+
1371
+ const client = new Client({
1372
+ node: 'https://localhost:9200',
1373
+ agent: new HttpProxyAgent('http://proxy.example.com:8080')
1374
+ });
1375
+ ```
1376
+
1377
+ ### Request and Response Serialization
1378
+
1379
+ ```javascript
1380
+ import { Client } from '@elastic/elasticsearch';
1381
+
1382
+ const client = new Client({
1383
+ node: 'https://localhost:9200',
1384
+ compression: 'gzip',
1385
+ enableMetaHeader: true
1386
+ });
1387
+ ```
1388
+
1389
+ ### Child Client
1390
+
1391
+ ```javascript
1392
+ const childClient = client.child({
1393
+ headers: {
1394
+ 'X-Custom-Header': 'child-value'
1395
+ }
1396
+ });
1397
+
1398
+ // Child client inherits parent configuration but can override
1399
+ const result = await childClient.search({
1400
+ index: 'products',
1401
+ query: { match_all: {} }
1402
+ });
1403
+ ```
1404
+
1405
+ ## Advanced Features
1406
+
1407
+ ### Point in Time (PIT)
1408
+
1409
+ ```javascript
1410
+ // Open PIT
1411
+ const pitResult = await client.openPointInTime({
1412
+ index: 'products',
1413
+ keep_alive: '1m'
1414
+ });
1415
+
1416
+ const pitId = pitResult.id;
1417
+
1418
+ // Search with PIT
1419
+ const searchResult = await client.search({
1420
+ size: 100,
1421
+ query: { match_all: {} },
1422
+ pit: {
1423
+ id: pitId,
1424
+ keep_alive: '1m'
1425
+ },
1426
+ sort: [{ _shard_doc: 'asc' }]
1427
+ });
1428
+
1429
+ // Close PIT
1430
+ await client.closePointInTime({
1431
+ id: pitId
1432
+ });
1433
+ ```
1434
+
1435
+ ### Search After for Deep Pagination
1436
+
1437
+ ```javascript
1438
+ // Initial search
1439
+ let result = await client.search({
1440
+ index: 'products',
1441
+ size: 100,
1442
+ query: { match_all: {} },
1443
+ sort: [
1444
+ { price: 'asc' },
1445
+ { _id: 'asc' }
1446
+ ]
1447
+ });
1448
+
1449
+ let hits = result.hits.hits;
1450
+
1451
+ // Get next page
1452
+ if (hits.length > 0) {
1453
+ const lastHit = hits[hits.length - 1];
1454
+
1455
+ result = await client.search({
1456
+ index: 'products',
1457
+ size: 100,
1458
+ query: { match_all: {} },
1459
+ sort: [
1460
+ { price: 'asc' },
1461
+ { _id: 'asc' }
1462
+ ],
1463
+ search_after: lastHit.sort
1464
+ });
1465
+ }
1466
+ ```
1467
+
1468
+ ### Explain API
1469
+
1470
+ ```javascript
1471
+ const result = await client.explain({
1472
+ index: 'products',
1473
+ id: 'product-123',
1474
+ query: {
1475
+ match: {
1476
+ name: 'laptop'
1477
+ }
1478
+ }
1479
+ });
1480
+
1481
+ console.log(result.explanation);
1482
+ ```
1483
+
1484
+ ### Validate Query
1485
+
1486
+ ```javascript
1487
+ const result = await client.indices.validateQuery({
1488
+ index: 'products',
1489
+ query: {
1490
+ match: {
1491
+ name: 'laptop'
1492
+ }
1493
+ }
1494
+ });
1495
+
1496
+ console.log('Valid:', result.valid);
1497
+ ```
1498
+
1499
+ ### Analyze API
1500
+
1501
+ ```javascript
1502
+ const result = await client.indices.analyze({
1503
+ analyzer: 'standard',
1504
+ text: 'Quick brown fox'
1505
+ });
1506
+
1507
+ result.tokens.forEach(token => {
1508
+ console.log(token.token);
1509
+ });
1510
+ ```
1511
+
1512
+ ### Index Template
1513
+
1514
+ ```javascript
1515
+ await client.indices.putIndexTemplate({
1516
+ name: 'products_template',
1517
+ index_patterns: ['products-*'],
1518
+ template: {
1519
+ settings: {
1520
+ number_of_shards: 2,
1521
+ number_of_replicas: 1
1522
+ },
1523
+ mappings: {
1524
+ properties: {
1525
+ name: { type: 'text' },
1526
+ price: { type: 'float' }
1527
+ }
1528
+ }
1529
+ }
1530
+ });
1531
+ ```
1532
+
1533
+ ### Component Template
1534
+
1535
+ ```javascript
1536
+ await client.cluster.putComponentTemplate({
1537
+ name: 'products_settings',
1538
+ template: {
1539
+ settings: {
1540
+ number_of_shards: 2
1541
+ }
1542
+ }
1543
+ });
1544
+
1545
+ await client.cluster.putComponentTemplate({
1546
+ name: 'products_mappings',
1547
+ template: {
1548
+ mappings: {
1549
+ properties: {
1550
+ name: { type: 'text' },
1551
+ price: { type: 'float' }
1552
+ }
1553
+ }
1554
+ }
1555
+ });
1556
+ ```
1557
+
1558
+ ### Cluster Health
1559
+
1560
+ ```javascript
1561
+ const result = await client.cluster.health();
1562
+
1563
+ console.log('Status:', result.status);
1564
+ console.log('Nodes:', result.number_of_nodes);
1565
+ console.log('Active shards:', result.active_shards);
1566
+ ```
1567
+
1568
+ ### Cat APIs
1569
+
1570
+ ```javascript
1571
+ // Cat indices
1572
+ const indices = await client.cat.indices({ format: 'json' });
1573
+ console.log(indices);
1574
+
1575
+ // Cat nodes
1576
+ const nodes = await client.cat.nodes({ format: 'json' });
1577
+ console.log(nodes);
1578
+
1579
+ // Cat health
1580
+ const health = await client.cat.health({ format: 'json' });
1581
+ console.log(health);
1582
+
1583
+ // Cat count
1584
+ const count = await client.cat.count({ format: 'json' });
1585
+ console.log(count);
1586
+ ```
1587
+
1588
+ ### Ingest Pipelines
1589
+
1590
+ ```javascript
1591
+ // Create pipeline
1592
+ await client.ingest.putPipeline({
1593
+ id: 'lowercase_processor',
1594
+ processors: [
1595
+ {
1596
+ lowercase: {
1597
+ field: 'name'
1598
+ }
1599
+ }
1600
+ ]
1601
+ });
1602
+
1603
+ // Use pipeline when indexing
1604
+ await client.index({
1605
+ index: 'products',
1606
+ pipeline: 'lowercase_processor',
1607
+ document: {
1608
+ name: 'LAPTOP',
1609
+ price: 999
1610
+ }
1611
+ });
1612
+
1613
+ // Get pipeline
1614
+ const pipeline = await client.ingest.getPipeline({
1615
+ id: 'lowercase_processor'
1616
+ });
1617
+ ```
1618
+
1619
+ ### Simulate Pipeline
1620
+
1621
+ ```javascript
1622
+ const result = await client.ingest.simulate({
1623
+ id: 'lowercase_processor',
1624
+ docs: [
1625
+ {
1626
+ _source: {
1627
+ name: 'LAPTOP'
1628
+ }
1629
+ }
1630
+ ]
1631
+ });
1632
+
1633
+ console.log(result.docs);
1634
+ ```