Skip to content

Commit

Permalink
Code changes for Indexer Operations in Search Service (#8225)
Browse files Browse the repository at this point in the history
* Code changes for list indexers operation.

* Code changes for create indexer operation

* Code changes for Get Indexer operation

* Code changes for create/update indexer

* Code changes for Delete indexer operation

* Code changes for Get Indexer Status operation

* Code changes for reset index operation

* Code changes for run index operation

* Remove select & change indexer name in Readme file

* Adding fields to List Ops

* PR Comments
  • Loading branch information
sarangan12 authored Apr 7, 2020
1 parent 47cfb37 commit 1490b99
Show file tree
Hide file tree
Showing 6 changed files with 545 additions and 19 deletions.
97 changes: 97 additions & 0 deletions sdk/search/search-documents/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,26 @@ async function main() {
main();
```

#### Get a list of existing indexers in the service
```js
const { SearchServiceClient, AzureKeyCredential } = require("@azure/search-documents");

const client = new SearchServiceClient("<endpoint>", new AzureKeyCredential("<apiKey>"));

async function main() {
let listOfIndexers = await client.listIndexers();

for(let indexer of listOfIndexers) {
console.log(`Name: ${indexer.name}`);
console.log(`Datasource Name: ${indexer.dataSourceName}`);
console.log(`Skillset Name: ${indexer.skillsetName}`);
console.log();
}
}

main();
```

#### Create an Index

```js
Expand Down Expand Up @@ -719,6 +739,32 @@ async function main() {
main();
```

#### Create an Indexer
```js
const { SearchServiceClient, AzureKeyCredential } = require("@azure/search-documents");

const client = new SearchServiceClient("<endpoint>", new AzureKeyCredential("<apiKey>"));

async function main() {
const indexer = await client.createIndexer({
name: 'my-azure-indexer-1',
description: "My Azure Indexer 1",
dataSourceName: "testblobstoragesjama",
targetIndexName: "azureblob-index-2",
isDisabled: false,
fieldMappings: [{
sourceFieldName: "metadata_storage_path",
targetFieldName: "metadata_storage_path",
mappingFunction: {
name: "base64Encode"
}
}]
});
}

main();
```

#### Create a SynonymMap

```js
Expand All @@ -736,6 +782,57 @@ async function main() {
main();
```

#### Retrieve an existing indexer and modify a field in it
```js
const { SearchServiceClient, AzureKeyCredential } = require("@azure/search-documents");

const client = new SearchServiceClient("<endpoint>", new AzureKeyCredential("<apiKey>"));

async function main() {
const indexer = await client.getIndexer("my-azure-indexer-1");
indexer.isDisabled = true;
indexer = await client.createOrUpdateIndexer(indexer);

console.log(`Name: ${indexer.name}`);
console.log(`Description: ${indexer.description}`);
console.log(`Datasource Name: ${indexer.dataSourceName}`);
console.log(`Target Index Name: ${indexer.targetIndexName}`);
console.log(`IsDisabled: ${indexer.isDisabled}`);
console.log(`Field Mappings`);
for(let fieldMapping of indexer.fieldMappings) {
console.log(`\tSource Field Name: ${fieldMapping.sourceFieldName}`);
console.log(`\tTarget Field Name: ${fieldMapping.targetFieldName}`);
console.log(`\tMapping Function Name: ${fieldMapping.mappingFunction.name}`);
}
}



main();
```

### Get the status of an indexer
```js
const { SearchServiceClient, AzureKeyCredential } = require("@azure/search-documents");

const client = new SearchServiceClient("<endpoint>", new AzureKeyCredential("<apiKey>"));

async function main() {
const indexerStatus = await client.getIndexerStatus('my-azure-indexer-1');
console.log(`Name: ${indexerStatus.name}`);
console.log(`OData Context: ${indexerStatus["@odata.context"]}`);
console.log(`Status: ${indexerStatus.status}`);
console.log(`Execution History`);
for(let execution of indexerStatus.executionHistory) {
console.log(`\tStatus: ${execution.status}`);
console.log(`\tFinal Tracking State: ${execution.finalTrackingState}`);
console.log(`\tInitial Tracking State: ${execution.initialTrackingState}`);
}
}

main();
```

## Troubleshooting

### Enable logs
Expand Down
146 changes: 140 additions & 6 deletions sdk/search/search-documents/review/search-documents.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,15 @@ export interface CorsOptions {
// @public
export type CountDocumentsOptions = OperationOptions;

// @public
export type CreateIndexerOptions = OperationOptions;

// @public
export type CreateIndexOptions = OperationOptions;

// @public
export type CreateorUpdateIndexerOptions = OperationOptions & ETagOperationOptions;

// @public
export interface CreateOrUpdateIndexOptions extends OperationOptions, ETagOperationOptions {
allowIndexDowntime?: boolean;
Expand Down Expand Up @@ -193,6 +199,9 @@ export interface DefaultCognitiveServicesAccount {
// @public
export type DeleteDocumentsOptions = IndexDocuments;

// @public
export type DeleteIndexerOptions = OperationOptions & ETagOperationOptions;

// @public
export type DeleteIndexOptions = OperationOptions & ETagOperationOptions;

Expand Down Expand Up @@ -307,6 +316,21 @@ export interface FacetResult {
// @public
export type Field = SimpleField | ComplexField;

// @public
export interface FieldMapping {
mappingFunction?: FieldMappingFunction;
sourceFieldName: string;
targetFieldName?: string;
}

// @public
export interface FieldMappingFunction {
name: string;
parameters?: {
[propertyName: string]: any;
};
}

// @public
export interface FreshnessScoringFunction {
boost: number;
Expand Down Expand Up @@ -334,6 +358,12 @@ export interface GetDocumentOptions<Fields> extends OperationOptions {
selectedFields?: Fields[];
}

// @public
export type GetIndexerOptions = OperationOptions;

// @public
export type GetIndexerStatusOptions = OperationOptions;

// @public
export type GetIndexOptions = OperationOptions;

Expand Down Expand Up @@ -415,6 +445,66 @@ export interface IndexDocumentsResult {
readonly results: IndexingResult[];
}

// @public
export interface Indexer {
dataSourceName: string;
description?: string;
etag?: string;
fieldMappings?: FieldMapping[];
isDisabled?: boolean;
name: string;
outputFieldMappings?: FieldMapping[];
parameters?: IndexingParameters;
schedule?: IndexingSchedule;
skillsetName?: string;
targetIndexName: string;
}

// @public
export interface IndexerExecutionInfo {
readonly executionHistory: IndexerExecutionResult[];
readonly lastResult?: IndexerExecutionResult;
readonly limits: IndexerLimits;
readonly status: IndexerStatus;
}

// @public
export interface IndexerExecutionResult {
readonly endTime?: Date;
readonly errorMessage?: string;
readonly errors: ItemError[];
readonly failedItemCount: number;
readonly finalTrackingState?: string;
readonly initialTrackingState?: string;
readonly itemCount: number;
readonly startTime?: Date;
readonly status: IndexerExecutionStatus;
readonly warnings: ItemWarning[];
}

// @public
export type IndexerExecutionStatus = 'transientFailure' | 'success' | 'inProgress' | 'reset';

// @public
export interface IndexerLimits {
readonly maxDocumentContentCharactersToExtract?: number;
readonly maxDocumentExtractionSize?: number;
readonly maxRunTime?: string;
}

// @public
export type IndexerStatus = 'unknown' | 'error' | 'running';

// @public
export interface IndexingParameters {
batchSize?: number;
configuration?: {
[propertyName: string]: any;
};
maxFailedItems?: number;
maxFailedItemsPerBatch?: number;
}

// @public
export interface IndexingResult {
readonly errorMessage?: string;
Expand All @@ -423,6 +513,12 @@ export interface IndexingResult {
readonly succeeded: boolean;
}

// @public
export interface IndexingSchedule {
interval: string;
startTime?: Date;
}

// @public
export interface InputFieldMappingEntry {
inputs?: InputFieldMappingEntry[];
Expand All @@ -431,6 +527,25 @@ export interface InputFieldMappingEntry {
sourceContext?: string;
}

// @public
export interface ItemError {
readonly details?: string;
readonly documentationLink?: string;
readonly errorMessage: string;
readonly key?: string;
readonly name?: string;
readonly statusCode: number;
}

// @public
export interface ItemWarning {
readonly details?: string;
readonly documentationLink?: string;
readonly key?: string;
readonly message: string;
readonly name?: string;
}

// @public
export interface KeepTokenFilter {
keepWords: string[];
Expand Down Expand Up @@ -660,8 +775,13 @@ export interface LimitTokenFilter {
}

// @public
export interface ListIndexesOptions extends OperationOptions {
select?: string[];
export interface ListIndexersOptions<Fields> extends OperationOptions {
select?: Fields[];
}

// @public
export interface ListIndexesOptions<Fields> extends OperationOptions {
select?: Fields[];
}

// @public
Expand All @@ -673,8 +793,8 @@ export interface ListSearchResultsPageSettings {
export type ListSkillsetsOptions = OperationOptions;

// @public
export interface ListSynonymMapsOptions extends OperationOptions {
select?: string[];
export interface ListSynonymMapsOptions<Fields> extends OperationOptions {
select?: Fields[];
}

// @public
Expand Down Expand Up @@ -884,6 +1004,12 @@ export interface RawSearchRequest {
// @public
export type RegexFlags = 'CANON_EQ' | 'CASE_INSENSITIVE' | 'COMMENTS' | 'DOTALL' | 'LITERAL' | 'MULTILINE' | 'UNICODE_CASE' | 'UNIX_LINES';

// @public
export type ResetIndexerOptions = OperationOptions;

// @public
export type RunIndexerOptions = OperationOptions;

// @public
export type ScoringFunction = DistanceScoringFunction | FreshnessScoringFunction | MagnitudeScoringFunction | TagScoringFunction;

Expand Down Expand Up @@ -986,22 +1112,30 @@ export class SearchServiceClient {
analyzeText(indexName: string, options: AnalyzeTextOptions): Promise<AnalyzeResult>;
readonly apiVersion: string;
createIndex(index: Index, options?: CreateIndexOptions): Promise<Index>;
createIndexer(indexer: Indexer, options?: CreateIndexerOptions): Promise<Indexer>;
createOrUpdateIndex(index: Index, options?: CreateOrUpdateIndexOptions): Promise<Index>;
createOrUpdateIndexer(indexer: Indexer, options?: CreateorUpdateIndexerOptions): Promise<Indexer>;
createOrUpdateSkillset(skillset: Skillset, options?: CreateOrUpdateSkillsetOptions): Promise<Skillset>;
createOrUpdateSynonymMap(synonymMap: SynonymMap, options?: CreateOrUpdateSynonymMapOptions): Promise<SynonymMap>;
createSkillset(skillset: Skillset, options?: CreateSkillsetOptions): Promise<Skillset>;
createSynonymMap(synonymMap: SynonymMap, options?: CreateSynonymMapOptions): Promise<SynonymMap>;
deleteIndex(indexName: string, options?: DeleteIndexOptions): Promise<void>;
deleteIndexer(indexerName: string, options?: DeleteIndexerOptions): Promise<void>;
deleteSkillset(skillsetName: string, options?: DeleteSkillsetOptions): Promise<void>;
deleteSynonymMap(synonymMapName: string, options?: DeleteSynonymMapOptions): Promise<void>;
readonly endpoint: string;
getIndex(indexName: string, options?: GetIndexOptions): Promise<Index>;
getIndexer(indexerName: string, options?: GetIndexerOptions): Promise<Indexer>;
getIndexerStatus(indexerName: string, options?: GetIndexerStatusOptions): Promise<IndexerExecutionInfo>;
getIndexStatistics(indexName: string, options?: GetIndexStatisticsOptions): Promise<GetIndexStatisticsResult>;
getSkillset(skillsetName: string, options?: GetSkillSetOptions): Promise<Skillset>;
getSynonymMap(synonymMapName: string, options?: GetSynonymMapsOptions): Promise<SynonymMap>;
listIndexes(options?: ListIndexesOptions): Promise<Index[]>;
listIndexers<Fields extends keyof Indexer>(options?: ListIndexersOptions<Fields>): Promise<Array<Pick<Indexer, Fields>>>;
listIndexes<Fields extends keyof Index>(options?: ListIndexesOptions<Fields>): Promise<Array<Pick<Index, Fields>>>;
listSkillsets(options?: ListSkillsetsOptions): Promise<Skillset[]>;
listSynonymMaps(options?: ListSynonymMapsOptions): Promise<SynonymMap[]>;
listSynonymMaps<Fields extends keyof SynonymMap>(options?: ListSynonymMapsOptions<Fields>): Promise<Array<Pick<SynonymMap, Fields>>>;
resetIndexer(indexerName: string, options?: ResetIndexerOptions): Promise<void>;
runIndexer(indexerName: string, options?: RunIndexerOptions): Promise<void>;
}

// @public
Expand Down
24 changes: 22 additions & 2 deletions sdk/search/search-documents/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,15 @@ export {
ComplexDataType,
CognitiveServicesAccount,
Skill,
SynonymMap
SynonymMap,
ListIndexersOptions,
CreateIndexerOptions,
GetIndexerOptions,
CreateorUpdateIndexerOptions,
DeleteIndexerOptions,
GetIndexerStatusOptions,
ResetIndexerOptions,
RunIndexerOptions
} from "./serviceModels";
export { default as GeographyPoint } from "./geographyPoint";
export { odata } from "./odata";
Expand Down Expand Up @@ -183,6 +191,18 @@ export {
VisualFeature,
KeyPhraseExtractionSkillLanguage,
OcrSkillLanguage,
TextExtractionAlgorithm
TextExtractionAlgorithm,
Indexer,
FieldMapping,
IndexingParameters,
IndexingSchedule,
FieldMappingFunction,
IndexerExecutionInfo,
IndexerExecutionResult,
IndexerLimits,
IndexerStatus,
ItemError,
IndexerExecutionStatus,
ItemWarning
} from "./generated/service/models";
export { AzureKeyCredential } from "@azure/core-auth";
Loading

0 comments on commit 1490b99

Please sign in to comment.