dr11
dr11

Reputation: 5756

Extend Azure Search fields with Cosmos DB indexer

I have a multiple Cosmos DB document types which are aggregated into a single Azure Search index.

For each document type I have a data source + indexer pair. It is an autogenerated pair that maps from Cosmos DB document fields into the index.

I faced with an issue: I generated a new indexer + data source for a new document type. I see that indexer completed the indexing. But my Index does not contain new fields. And I can't even add a new field manually, which will contain the data added by indexer.

Basing on docs it is possible to add a new field without rebuilding the index. But it's not clear how exactly this can be done

Upvotes: 0

Views: 135

Answers (1)

Sophiac
Sophiac

Reputation: 173

What problem are you seeing when you try to add the new index field manually? You should be able to add a new field to the index definition with a new field via REST or the portal interface.

Via portal: Navigate to your search service, select appropriate index from list, click on the "Fields" tab and click "Add field". A new field should show up at the bottom of the index grid and you should be able to edit field attributes/name/type.

Via REST: You have the right link to the update operation. You can do a GET on the existing index definition and add your new field to the "fields" array before using PUT for update. Your new index field JSON should be similar to the other fields in the index, for example:

"fields": [
...,
{
    "name": "new field",
    "type": "Edm.String",
    "facetable": false,
    "filterable": false,
    "key": false,
    "retrievable": true,
    "searchable": true,
    "sortable": false,
    "analyzer": "standard.lucene",
    "indexAnalyzer": null,
    "searchAnalyzer": null,
    "synonymMaps": [],
    "fields": []
}
]

Here's a doc reference on the index definition JSON.

Be sure to set index field attributes (Filterable, Sortable, Searchable...) on new field creation as not all attributes can be added without rebuilding the index. Only retrievable, searchAnalyzer, and synonymMaps can be modified to an existing field.

Upvotes: 0

Related Questions