Skip to main content

A decorator to check for indexing status errors

Project description

MeiliSearch Status Check Decorator

Tests Status pre-commit.ci status Coverage PyPI version PyPI - Python Version

This package provides a decorator for the MeiliSearch Python client that will check for a failed status when adding documents.

Instillation

pip install meilisearch-status-check-decorator

Useage

Add documents with no errors

In this example there will be no errors so the documents will be added and the decorator will not print anything.

from meilisearch import Client
from meilisearch_status_check_decorator import status_check

index = Client("http://localhost:7700", "masterKey").index("test")


@status_check(index=index)
def good_insert():
    documents = [
      {
        "id": 1,
        "name": "test 1",
      },
      {
        "id": 2,
        "name": "test 2",
      }
    ]
    index.add_documents(documents)

Add documents with errors

In this example an error will be returned because a primary key cannot be inferred

from meilisearch import Client
from meilisearch_status_check_decorator import status_check

index = Client("http://localhost:7700", "masterKey").index("test")


@status_check(index=index)
def bad_insert():
    documents = [
      {
        "name": "test 1",
      },
      {
        "name": "test 2",
      }
    ]
    index.add_documents(documents)

This will result in an error similar to the following being printed:

FAILED: {'status': 'failed', 'updateId': 0, 'type': {'name': 'DocumentsAddition'}, 'message': 'missing primary key', 'errorCode': 'missing_primary_key', 'errorType': 'invalid_request_error', 'errorLink': 'https://docs.meilisearch.com/errors#missing_primary_key', 'duration': 0.025, 'enqueuedAt': '2021-08-29T17:06:59.877177189Z', 'processedAt': '2021-08-29T17:06:59.906190045Z'}

Contributing

Contributions to this project are welcome. If you are interesting in contributing please see our contributing guide

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Built Distribution

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page