@@ -391,6 +391,128 @@ def add_documents_in_batches(
391
391
392
392
return update_ids
393
393
394
+ def add_documents_json (
395
+ self ,
396
+ str_documents : str ,
397
+ primary_key : Optional [str ] = None ,
398
+ ) -> Dict [str , int ]:
399
+ """Add string documents from JSON file to the index.
400
+
401
+ Parameters
402
+ ----------
403
+ str_documents:
404
+ String of document from a JSON file.
405
+ primary_key (optional):
406
+ The primary-key used in index. Ignored if already set up.
407
+
408
+ Returns
409
+ -------
410
+ update:
411
+ Dictionary containing an update id to track the action:
412
+ https://docs.meilisearch.com/reference/api/updates.html#get-an-update-status
413
+
414
+ Raises
415
+ ------
416
+ MeiliSearchApiError
417
+ An error containing details about why MeiliSearch can't process your request. MeiliSearch error codes are described here: https://docs.meilisearch.com/errors/#meilisearch-errors
418
+ """
419
+ return self .add_documents_raw (str_documents , primary_key , 'json' )
420
+
421
+ def add_documents_csv (
422
+ self ,
423
+ str_documents : str ,
424
+ primary_key : Optional [str ] = None ,
425
+ ) -> Dict [str , int ]:
426
+ """Add string documents from a CSV file to the index.
427
+
428
+ Parameters
429
+ ----------
430
+ str_documents:
431
+ String of document from a CSV file.
432
+ primary_key (optional):
433
+ The primary-key used in index. Ignored if already set up.
434
+
435
+ Returns
436
+ -------
437
+ update:
438
+ Dictionary containing an update id to track the action:
439
+ https://docs.meilisearch.com/reference/api/updates.html#get-an-update-status
440
+
441
+ Raises
442
+ ------
443
+ MeiliSearchApiError
444
+ An error containing details about why MeiliSearch can't process your request. MeiliSearch error codes are described here: https://docs.meilisearch.com/errors/#meilisearch-errors
445
+ """
446
+ return self .add_documents_raw (str_documents , primary_key , 'csv' )
447
+
448
+ def add_documents_ndjson (
449
+ self ,
450
+ str_documents : str ,
451
+ primary_key : Optional [str ] = None ,
452
+ ) -> Dict [str , int ]:
453
+ """Add string documents from a NDJSON file to the index.
454
+
455
+ Parameters
456
+ ----------
457
+ str_documents:
458
+ String of document from a NDJSON file.
459
+ primary_key (optional):
460
+ The primary-key used in index. Ignored if already set up.
461
+
462
+ Returns
463
+ -------
464
+ update:
465
+ Dictionary containing an update id to track the action:
466
+ https://docs.meilisearch.com/reference/api/updates.html#get-an-update-status
467
+
468
+ Raises
469
+ ------
470
+ MeiliSearchApiError
471
+ An error containing details about why MeiliSearch can't process your request. MeiliSearch error codes are described here: https://docs.meilisearch.com/errors/#meilisearch-errors
472
+ """
473
+ return self .add_documents_raw (str_documents , primary_key , 'jsonl' )
474
+
475
+ def add_documents_raw (
476
+ self ,
477
+ str_documents : str ,
478
+ primary_key : Optional [str ] = None ,
479
+ doc_type : Optional [str ] = None ,
480
+ ) -> Dict [str , int ]:
481
+ """Add string documents to the index.
482
+
483
+ Parameters
484
+ ----------
485
+ str_documents:
486
+ String of document.
487
+ primary_key (optional):
488
+ The primary-key used in index. Ignored if already set up.
489
+ type:
490
+ The type of document. Type available: 'csv', 'json', 'jsonl'
491
+
492
+ Returns
493
+ -------
494
+ update:
495
+ Dictionary containing an update id to track the action:
496
+ https://docs.meilisearch.com/reference/api/updates.html#get-an-update-status
497
+
498
+ Raises
499
+ ------
500
+ MeiliSearchApiError
501
+ An error containing details about why MeiliSearch can't process your request. MeiliSearch error codes are described here: https://docs.meilisearch.com/errors/#meilisearch-errors
502
+ """
503
+ if primary_key is None :
504
+ url = f'{ self .config .paths .index } /{ self .uid } /{ self .config .paths .document } '
505
+ else :
506
+ primary_key = urllib .parse .urlencode ({'primaryKey' : primary_key })
507
+ url = f'{ self .config .paths .index } /{ self .uid } /{ self .config .paths .document } ?{ primary_key } '
508
+ if doc_type == "json" :
509
+ content_type = 'application/json'
510
+ if doc_type == "jsonl" :
511
+ content_type = 'application/x-ndjson'
512
+ if doc_type == "csv" :
513
+ content_type = 'text/csv'
514
+ return self .http .post (url , str_documents , content_type )
515
+
394
516
def update_documents (
395
517
self ,
396
518
documents : List [Dict [str , Any ]],
0 commit comments