Programmatically updating Full Text Search index

I’d like to maintain my Full Text Indices in source control, but this is difficult because the uuid value gets updated on every mutation. Looks like, i have to:

  • Fetch the existing definition to get the latest uuid
  • Update new definition with this uuid
  • this put new definition into /api/index/{indexName}

Is this correct, the documentation in https://docs.couchbase.com/server/current/fts/fts-creating-indexes.html
says all I have to do is change uuid property to “”, but that only works on creates, not updates.

Hi @bfwarner,

The FTS index definition uuid gets changed with every index definition updates, not with the incoming mutations.
The index update steps you mentioned here is totally correct.
During index definition updates - you have to pass in the newly fetched uuid in the request.
If you should omit the uuid field only during index creations and with a non existing index name.

And the document also mentions the same ?
ref snippet from the doc link:

The simplest way to create the appropriate JSON index-definition for the body is to create an index by means of the Couchbase Web Console, make a copy of the JSON index-definition thereby produced (by accessing the Using the Index Definition Preview, explained above), modify the index-definition as appropriate, and finally, add the index-definition to the other, preceding elements required for the call. Note, however, that this requires modification of the uuid field; since the re-specifying of an existing field-value is interpreted as an attempted update, to an existing index. Therefore, if the uuid field for an existing index appears in the Index Definition Preview as "uuid": "3402702ff3c862c0", it should be edited to appear "uuid": "". A new ID will be allocated to the new index, and this ID will appear in the Index Definition Preview for the new index.

So it mentions about the newer index creation.

Cheers!

The admin console so does not allow me to update existing indexes by setting uuid to “”, I have to query the database for the existing uuid and use that to update the index.

From the UI, you just need to try the “Edit” button/option for updating the index definition. If there are no other concurrent threads updating the index definitions in the background over the rest endpoint, this should work correctly.
ie, you don’t have to worry about the uuid edit while trying the index updates from the UI.

Cheers!

Blockquote
The admin console so does not allow me to update existing indexes by setting uuid to “”

This is wrong, as you are not supposed to set the uuid to empty for updating the index definition. UUID field is omitted for new index creation. UUID is overridden with the existing uuid value for index defn updates.

Ok, the rest interface does not allow me to update existing indexes by setting uuid to “”, I have the fetch the value from the db.

Blockquote Ok, the rest interface does not allow me to update existing indexes by setting uuid to “”, I have the fetch the value from the db.

uuid=“” isn’t an option, you have to give the latest index uuid:“$latestUUID” value there for updating the index.