Skip to content

Commit 7021b40

Browse files
pcasanodkz
andauthored
fix: allow for alias index name to return mapping (#93)
* 92: Allow for alias index name to return mapping * remove redundant comment Co-authored-by: Pablo Damnhorns <[email protected]>
1 parent f6bc025 commit 7021b40

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/utils.js

+8-7
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,13 @@ export async function fetchElasticMapping(
115115
);
116116
}
117117

118-
const elasticMapping = (
119-
await opts.elasticClient.indices.getMapping({
120-
index: opts.elasticIndex,
121-
type: opts.elasticType,
122-
})
123-
)[opts.elasticIndex].mappings[opts.elasticType];
118+
const elasticMapping = await opts.elasticClient.indices.getMapping({
119+
index: opts.elasticIndex,
120+
type: opts.elasticType,
121+
});
122+
123+
// Try index name, else resort to Value in case Index name is an alias
124+
const baseIndex = elasticMapping[opts.elasticIndex] || Object.values(elasticMapping)[0];
124125

125-
return elasticMapping;
126+
return baseIndex.mappings[opts.elasticType];
126127
}

0 commit comments

Comments
 (0)