Document Management
Documents are JSON objects that are stored in a Searchcraft index. They represent a single record of your data that is optimized for search. Each document has two id fields, id
which is the identifier from the source data system (your CMS, database, etc) and _id
which is the internal Searchcraft ID. Documents do not need to contain all fields from the source record, just the fields you want to search against and display in search results.
If you are using a CMS integration you do not need to use these endpoints, the CMS integration will handle this for you.
API Endpoints
POST /index/:index/documents
Add one or several documents to an index.DELETE /index/:index/documents
Delete one or several documents from an index by field term match.{title: foo}
or{id: "xyz"}
GET /index/:index/documents/:document_id
Get a single document from an index by it’s internal Searchcraft ID (_id).DELETE /index/:index/documents/:document_id
Delete a single document from an index by it’s internal Searchcraft ID (_id).DELETE /index/:index/documents/query
Delete one or several documents from an index by QUERY match.DELETE /index/:index/documents/all
Delete all documents from an index.
Auth Requirement
Requires an authentication key that has ingestion permissions.
Insert Documents
You can insert one or more documents into an index at once. If you are planning on inserting a large number of documents in a row it’s recommended to batch them into multiple larger requests rathn than sending them one at a time.
Example:
curl -X POST -H "Content-Type: application/json" -H "Authorization: ingest-key-value" --data '[{"id": "5", "title": "Lorem ipsum dolor sit amet, consectetur adipiscing elit.", "body": "Maecenas sed mauris commodo ligula porttitor euismod a vitae nunc. Nam placerat consequat arcu, ut consectetur nisi feugiat eget. Nam in tellus vel ligula cursus sollicitudin non id ex. Praesent sollicitudin ultrices tempor. Phasellus sed tortor tristique, vehicula augue quis, sagittis enim. Praesent egestas vitae mi vitae egestas. Mauris eget interdum est. Maecenas in purus sed erat varius tempor ut in massa. Sed neque risus, semper iaculis metus quis, aliquet ultricies felis. Praesent dictum id sapien sed vehicula.", "categories": ["category_1", "category_2"]}]' https://searchcraft-cluster-url/index/:index_name/documents
Delete Documents
When deleting an individual document you most likely want to use the source ID (your id
field) not the Searchcraft _id
field.
Example:
curl -X DELETE -H "Content-Type: application/json" -H "Authorization: ingest-key-value" --data '{"id": "12345"}' https://searchcraft-cluster-url/index/:index_name/documents
You may delete all docuents from an index by using the DELETE /index/:index/documents/all
endpoint. An index will continue to exist after all documents are deleted.