Keep your index up to date

You can keep your Helix Core server index up to date by using one of the following methods.

Manually update the index

Index individual changes

Index a specific change. This will create a new index if one does not exist or update an existing index.

GET http://localhost:1601/api/v1.1/index/change/<change_number>

Example

To index change number 917503, use the following curl request:

curl -H 'X-Auth-Token: <YOUR-AUTH-TOKEN>' http://localhost:1601/api/v1.1/index/change/917503

Elasticsearch responds with:

"OK"

Remove obliterated files from the index

When a file is obliterated from the Helix server, this endpoint can be used to remove it from the index.

POST http://localhost:1601/api/v1.1/index/obliterate"

Example

To remove the //streams-depot/main-stream-ProjB/Jenkinsfile and "depot/project2/NewScript1.m#2" files from the index:

POST http://localhost:1601/api/v1/obliterate
X-Auth-Token: <YOUR-AUTH-TOKEN>
Accept: application/json
 
{
  "argsQuoted":"//streams-depot/main-stream-ProjB/Jenkinsfile,//depot/project2/NewScript1.m@12",
  "client":"super_proj",
  "clientcwd":"/Users/bruno/Workspaces/super_proj"
}

Elasticsearch responds with:

"OK"

For information on removing individual files or the content of a directory, see Remove obliterated files from the index.

Use a Perforce Lua extension

Important

Lua extensions are not supported when your Helix server is installed on a Windows computer. To keep your index up to date when Helix server is installed on Windows use a Helix server trigger, see Use a Helix server trigger.

Index individual changes

You can create a server-side extension on Helix server with a Lua script to call the index change endpoint in the same way as shown above.

Remove obliterated files from the index

When a file is obliterated from the Helix server, you can automatically remove it from the index with a server-side extension Lua script to call the index obliterate endpoint, in the same way as shown above.

Writing a cron job

You can write a cron job to keep the index up to date. The cron job can call the changes index endpoint with specific from and to change numbers, see Indexing changes.

Use a Helix server trigger

Tip

If your Helix server is installed on Linux or MacOS, it is easier to use Lua extensions to keep your index up to date, see Use a Perforce Lua extension.

Index individual changes

You can create a trigger on your Helix server to call the index change endpoint in the same way as shown above using a shell script.

To create the trigger script and add it to your Helix server:

  1. Create a trigger script file.

    Make sure you change the Uri from http://p4search.mydomain.com:1601 to suit your configuration.

  2. Example:

    $token = $args[0]
    $change = $args[1]
    $Header = @{
        "X-Auth-Token" = "$token"
    }
    $Parameters = @{
        Method      = "GET" 
        Uri         = "http://p4search.mydomain.com:1601/api/v1.1/index/change/$change"
        Headers     = $Header
        ContentType = "application/json"
    }
    Invoke-RestMethod @Parameters

  3. Save your trigger script file as helix-core-search-indexer.ps1.

  4. Add the helix-core-search-indexer.ps1 file to your Helix server, preferably at //depot/triggers/....

  5. Edit the triggers table by running p4 triggers and add the following to the triggers table. Make sure you change the X-Auth-Token to suit your configuration:

  6. helix-core-search-indexer change-commit //... "powershell.exe %//depot/triggers/helix-core-search-indexer.ps1% 00000000-0000-0000-0000-000000000000 %change%"

    Your Helix server Search Index end point will index every change that is submitted.

For more information on triggers, see Triggers in the Helix Core Server Administrator Guide.

Remove obliterated files from the index

You can create a trigger script to remove obliterated files from the index.

To create the trigger script and add it to your Helix server:

  1. Create a trigger script file.

    Make sure you change the Uri from http://p4search.mydomain.com:1601 to suit your configuration.

  2. Example:

    $token = $args[0]
    $argc = $args[1]
    $yparam = $args[2]
    # Write-Host $args
    # Check for -y option then call the end point
    $dashy = $yparam -Contains ("-y")
    # Write-Host $dashy
    If ($dashy) {
        $client = $args[$args.count - 2]
        $clientcwd = $args[$args.count - 1]
        # Write-Host $client
        # Write-Host $clientcwd
        $files = $args[3];
        for ($index = 4; $index -lt ($args.count-2); $index++) {
            $files = $files + "," + $args[$index]
        }
        Write-Host $files
        $Header = @{
          "X-Auth-Token" = "$token"
        }
        $BodyJson = @{
          "clientcwd" = "$clientcwd"
          "client" = "$client"
          "argsQuoted" = "$files"
        } | ConvertTo-Json
        $Parameters = @{
            Method      = "POST"
            Uri     = "http://p4search.mydomain.com:1601/api/v1.1/obliterate"
            Headers     = $Header
            ContentType = "application/json"
            Body        = $BodyJson
        }
        Invoke-RestMethod @Parameters
    } Else {
        Write-Host "-y not present. Not calling endpoint."
    }

  3. Save your trigger script file as helix-core-search-obliterate.ps1.

  4. Add the helix-core-search-obliterate.ps1 file to your Helix server, preferably at //depot/triggers/....

  5. Edit the triggers table by running p4 triggers and add the following to the triggers table. Make sure you change the X-Auth-Token to suit your configuration:

  6. helix-core-search-obliterate command pre-user-obliterate "powershell.exe %//depot/triggers/helix-core-search-obliterate.ps1% 00000000-0000-0000-0000-000000000000 %argc% %args% %client% %clientcwd%"

    Your Helix server Search Obliterate end point will remove obliterated files from the index.

For more information on triggers, see Triggers in the Helix Core Server Administrator Guide.

Useful topics