I'm trying to add a normalizer with a lowercase option to my mapping object as it is wrote in the official Elasticsearch documentation
Here is my mapping object:
const schema = {
date: {
type: 'date'
},
user: {
type: 'keyword'
},
environment: {
type: 'text'
}
};
const mappingBodySchema = {
settings: {
analysis: {
normalizer: {
logsNormalizer: {
// eslint-disable-next-line camelcase
filter: ['lowercase']
}
}
}
},
mappings: {
properties: schema
}
};
And the function from elastic-js-client that I'm using to set up logs:
await esclient.indices.putMapping({
index,
body: mappingBodySchema
});
But I'm receiving the following error: ResponseError: mapper_parsing_exception
.
Can somebody advise me how can I add normalizer to the mapping object properly?
I've found out how to add mapping via the elasticsearch-js-client:
/*
* Closing index to change its settings
* (A closed index is blocked for read/write operations and does not allow all operations that opened indices allow.)
*/
await esclient.indices.close({
index
});
await esclient.indices.putSettings({
index,
body: mapSettings
});
// Opening index after settings update - allows to perform read/write operations
await esclient.indices.open({
index
});
// Specifying the mapping object of our log
await esclient.indices.putMapping({
index,
body: {
properties: schema
}
});
using Type script
import { ElasticIndexs } from '@mylib/common';
import { Client } from '@elastic/elasticsearch';
export class Tag {
private schema = {
id: {
type: 'text',
},
name: {
type: 'keyword',
normalizer: 'useLowercase',
},
phtoto: {
type: 'text',
},
};
constructor(private client: Client) {
Object.setPrototypeOf(this, Tag.prototype);
}
async create() {
const settings = {
settings: {
analysis: {
normalizer: {
useLowercase: {
filter: ['lowercase'],
},
},
},
},
mappings: {
properties: this.schema,
},
};
const { body } = await this.client.indices.exists({
index: ElasticIndexs.Tags,
});
Promise.all([
(async (client) => {
await new Promise(async function (resolve, reject) {
if (!body) {
await client.indices.create({ index: ElasticIndexs.Tags });
}
resolve({ body });
});
})(this.client),
]);
await this.client.indices.close({ index: ElasticIndexs.Tags });
await this.client.indices.putSettings({
index: ElasticIndexs.Tags,
body: settings,
});
await this.client.indices.open({
index: ElasticIndexs.Tags,
});
await this.client.indices.putMapping({
index: ElasticIndexs.Tags,
body: {
properties: this.schema,
},
});
}
}
import { Client } from '@elastic/elasticsearch';
class ElasticWrapper {
private _client: Client = new Client({
node: process.env.elasticsearch_node,
auth: {
username: 'elastic',
password: process.env.elasticsearch_password || 'changeme',
},
ssl: {
ca: process.env.elasticsearch_certificate,
rejectUnauthorized: false,
},
});
get client() {
return this._client;
}
}
export const elasticWrapper = new ElasticWrapper();
new Tag(elasticWrapper.client).create();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.