azure-cognitive-searchazure-ai-search

Indexer status is not updating while running


The indexer status does not update from 'running' status to anything else, even though in my search resource on the Azure portal it shows that the indexer run is completed and the corresponding index is updated.

I tried two approaches:

  1. Using search python-sdk
from time import sleep
while True:
    indexer_status = client.get_indexer_status(indexer_name)
    status = indexer_status.status
    print(f"Indexer status: {status}")
    if status in ("running", "inProgress"):
        print("Indexer is still running. Waiting for 10 seconds...")
        sleep(10)
    else:
        print("Indexer has completed.")
        break
  1. GET request
import requests

# Construct the URL for the API request
url = f"https://{search_service_name}.search.windows.net/indexers/{indexer_name}/status?api-version={api_version}&failIfCannotDecrypt={fail_if_cannot_decrypt}"
headers = {"Content-Type": "application/json", "api-key": api_key}

# Make the GET request
response = requests.get(url, headers=headers)

# Check the status of the request
if response.status_code == 200:
    # If the request was successful, print the response
    print(response.json()["status"])
else:
    # If the request failed, print the status code and error message
    print(f"Request failed with status code {response.status_code}")
    print(response.text)

In the first approach the loop never ends and for the both approaches, querying status shows 'running'. Note that I performed these queries after checking the indexer has completed running on the azure portal.

Does running status mean indexer run is completed? but on the azure portal, I see two status - 'In progress' and 'Success'. I'm hoping to see 'Success' as status after the run completion. Why is this not showing up in my approach above? TIA


Solution

  • I think I've found a solution that works with the GET method, where you retrieve the status of the indexer from its execution history indexer_status = response.json()["executionHistory"][0]["status"]. Note that you probably have to wait for few mins if your indexer is newly created and does not have an execution history, I achieved this by running an infinite while loop which breaks when the indexer executionHistory key is not empty.