This tutorial will guide you through the first steps of using the Indexing API. Here you will learn how to add a document in the index, retrieve document content, remove a document, and more.

To start, you’ll need your index’s site key and secret API key. These can be found in the Keys and installation section of your AddSearch dashboard. In the examples below, make sure to replace the {site key} and {secret key} with your specific site and secret keys, as well as the specific URL.

Each document in AddSearch index has a unique ID, a string of characters. An ID of the document is usually specified in the end of the API request URL:
https://api.addsearch.com/v2/indices/{your index public key}/documents/{document ID}
All examples below use the {document ID} as “test”.

Once you have your keys, you can add your first document to your index. To do this, make a curl PUT request like the following:

Creating a document with a certain URL

curl --request PUT \
  --url https://api.addsearch.com/v2/indices/{your index public key}/documents/test \
  --user '{your index public key}:{your index secret key}' \
  --header 'Content-Type: application/json' \
  --data '{
	"url": "https://www.addsearch.com",
  "custom_fields": {
    "title": "Test document",
    "description": "Description for a test document",
    "page_rating": 4.5
  }
}'


Once you’ve added your first document to the index, you can confirm that this was successful and check the contents of that document using a curl GET request:

Getting document’s content

curl --request GET \
--url https://api.addsearch.com/v2/indices/{your index public key}/documents/test \
--user '{your index public key}:{your index secret key}'


If you need to delete a file from your index, this can be done with the following curl DELETE request:

Removing a document


curl --request DELETE \
--url https://api.addsearch.com/v2/indices/{your index public key}/documents/test \
--user '{your index public key}:{your index secret key}'

Once the index contains some documents, you can test the search.

Search


curl --request GET \
--url 'https://api.addsearch.com/v1/search/https://api.addsearch.com/v2/indices/{your index public key}?term=test'

Was this helpful?

Need more help?

We’re always happy to help with code or other questions you might have. Search our documentation, contact support, or connect with our sales team.