* Modify index/alias name handling.

* Change config key name to be all lowercase
* Documentation updates

Signed-off-by: Jussi Hallila <jussi@hallila.com>
This commit is contained in:
Jussi Hallila
2021-08-03 13:07:25 +02:00
parent d9c13d535b
commit 54e1280b6a
5 changed files with 29 additions and 17 deletions
+5 -5
View File
@@ -15,7 +15,7 @@ that environment variables for AWS access key id and secret access key are defin
```yaml
search:
elasticSearch:
elasticsearch:
provider: aws
node: https://my-backstage-search-asdfqwerty.eu-west-1.es.amazonaws.com
```
@@ -26,7 +26,7 @@ Elastic Cloud hosted ElasticSearch uses a Cloud ID to determine the instance of
```yaml
search:
elasticSearch:
elasticsearch:
provider: elastic
cloudId: backstage-elastic:asdfqwertyasdfqwertyasdfqwertyasdfqwerty==
auth:
@@ -44,7 +44,7 @@ Other ElasticSearch instances can be connected to by using standard ElasticSearc
```yaml
search:
elasticSearch:
elasticsearch:
node: http://localhost:9200
auth:
username: elastic
@@ -55,7 +55,7 @@ search:
```yaml
search:
elasticSearch:
elasticsearch:
node: http://localhost:9200
auth:
bearer: token
@@ -65,7 +65,7 @@ search:
```yaml
search:
elasticSearch:
elasticsearch:
node: http://localhost:9200
auth:
apiKey: base64EncodedKey
+8 -5
View File
@@ -60,6 +60,9 @@ ElasticSearch needs some additional configuration before it is ready to use
within your instance. The configuration options are documented in the
[configuration schema definition file.](https://github.com/backstage/backstage/blob/master/plugins/search-backend-module-elasticsearch/config.d.ts)
The underlying functionality is using official ElasticSearch client version 7.x,
meaning that ElasticSearch version 7 is the only one confirmed to be supported.
## Example configurations
### AWS
@@ -72,7 +75,7 @@ to the
```yaml
search:
elasticSearch:
elasticsearch:
provider: aws
node: https://my-backstage-search-asdfqwerty.eu-west-1.es.amazonaws.com
```
@@ -86,7 +89,7 @@ be provided either directly or using environment variables like defined in
```yaml
search:
elasticSearch:
elasticsearch:
provider: elastic
cloudId: backstage-elastic:asdfqwertyasdfqwertyasdfqwertyasdfqwerty==
auth:
@@ -113,7 +116,7 @@ and how to create a bearer token see
```yaml
search:
elasticSearch:
elasticsearch:
node: http://localhost:9200
auth:
username: elastic
@@ -124,7 +127,7 @@ search:
```yaml
search:
elasticSearch:
elasticsearch:
node: http://localhost:9200
auth:
bearer: token
@@ -134,7 +137,7 @@ search:
```yaml
search:
elasticSearch:
elasticsearch:
node: http://localhost:9200
auth:
apiKey: base64EncodedKey
+1 -1
View File
@@ -30,7 +30,7 @@ export default async function createPlugin({
config,
}: PluginEnvironment) {
// Initialize a connection to a search engine.
const searchEngine = config.has('search.elasticSearch')
const searchEngine = config.has('search.elasticsearch')
? await ElasticSearchSearchEngine.fromConfig({
logger,
config,
+2 -2
View File
@@ -20,7 +20,7 @@ export interface Config {
/**
* Options for ElasticSearch
*/
elasticSearch?:
elasticsearch?:
| // elastic = Elastic.co ElasticSearch provider
{
provider: 'elastic';
@@ -75,7 +75,7 @@ export interface Config {
* Authentication credentials for ElasticSearch
* If both ApiKey/Bearer token and username+password is provided, tokens take precedence
*/
auth: {
auth?: {
username?: string;
/**
@@ -87,7 +87,7 @@ export class ElasticSearchSearchEngine implements SearchEngine {
return new ElasticSearchSearchEngine(
await ElasticSearchSearchEngine.constructElasticSearchClient(
logger,
config.getConfig('search.elasticSearch'),
config.getConfig('search.elasticsearch'),
),
aliasPostfix,
indexPrefix,
@@ -251,7 +251,7 @@ export class ElasticSearchSearchEngine implements SearchEngine {
});
return {
results: result.body.hits.hits.map((d: ElasticSearchResult) => ({
type: d._index.split('__')[0],
type: this.getTypeFromIndex(d._index),
document: d._source,
})),
};
@@ -264,11 +264,20 @@ export class ElasticSearchSearchEngine implements SearchEngine {
}
}
private readonly indexSeparator = '-index__';
private constructIndexName(type: string, postFix: string) {
return `${this.indexPrefix}${type}-index__${postFix}`;
return `${this.indexPrefix}${type}${this.indexSeparator}${postFix}`;
}
private getTypeFromIndex(index: string) {
return index
.substring(this.indexPrefix.length)
.split(this.indexSeparator)[0];
}
private constructSearchAlias(type: string) {
return `${this.indexPrefix}${type}__${this.aliasPostfix}`;
const postFix = this.aliasPostfix ? `__${this.aliasPostfix}` : '';
return `${this.indexPrefix}${type}${postFix}`;
}
}