Skip to content

Commit

Permalink
feat: new option 'indexMappingTotalFieldsLimit'
Browse files Browse the repository at this point in the history
  • Loading branch information
walterra committed Oct 12, 2023
1 parent d51034d commit 92edad1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -115,6 +115,7 @@ transformer({
- `targetIndexName`: The target Elasticsearch index where documents will be indexed.
- `mappings`: Optional Elasticsearch document mappings. If not set and you're reindexing from another index, the mappings from the existing index will be used.
- `mappingsOverride`: If you're reindexing and this is set to `true`, `mappings` will be applied on top of the source index's mappings. Defaults to `false`.
- `indexMappingTotalFieldsLimit`: Optional field limit for the target index to be created that will be passed on as the `index.mapping.total_fields.limit` setting.
- `query`: Optional Elasticsearch [DSL query](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl.html) to filter documents from the source index.
- `skipHeader`: If true, skips the first line of the source file. Defaults to `false`.
- `transform(line)`: A callback function which allows the transformation of a source line into one or several documents.
Expand Down
18 changes: 13 additions & 5 deletions src/_create-mapping.js
Expand Up @@ -5,6 +5,7 @@ export default function createMappingFactory({
targetIndexName,
mappings,
mappingsOverride,
indexMappingTotalFieldsLimit,
verbose,
}) {
return async () => {
Expand Down Expand Up @@ -32,12 +33,19 @@ export default function createMappingFactory({
}

try {
const resp = await targetClient.indices.create(
{
index: targetIndexName,
body: { mappings: targetMappings },
const resp = await targetClient.indices.create({
index: targetIndexName,
body: {
mappings: targetMappings,
...(indexMappingTotalFieldsLimit !== undefined
? {
settings: {
'index.mapping.total_fields.limit': indexMappingTotalFieldsLimit,
},
}
: {}),
},
);
});
if (verbose) console.log('Created target mapping', resp);
} catch (err) {
console.log('Error creating target mapping', err);
Expand Down
2 changes: 2 additions & 0 deletions src/main.js
Expand Up @@ -16,6 +16,7 @@ export default async function transformer({
targetIndexName,
mappings,
mappingsOverride = false,
indexMappingTotalFieldsLimit,
query,
skipHeader = false,
transform,
Expand All @@ -41,6 +42,7 @@ export default async function transformer({
targetIndexName,
mappings,
mappingsOverride,
indexMappingTotalFieldsLimit,
verbose,
});
const indexer = indexQueueFactory({
Expand Down

0 comments on commit 92edad1

Please sign in to comment.