问题
I'm trying to create a mapping between MongoDB and elasticsearch. I'm using mongoosastic for it. When I'm trying to create new mapping it gives me following error.
For solution, i have add ?Finclude_type_name=true
on https://github.com/mongoosastic/mongoosastic/blob/master/lib/mongoosastic.js
function createMappingIfNotPresent (options, cb) {
const client = options.client;
const indexName = options.indexName;
const typeName = options.typeName+"?Finclude_type_name=true";
const schema = options.schema;
const settings = options.settings;
const properties = options.properties;
response: '{"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"Types cannot be provided in put mapping requests, unless the include_type_name parameter is set to true."}],"type":"illegal_argument_exception","reason":"Types cannot be provided in put mapping requests, unless the include_type_name parameter is set to true."},"status":400}',
I have no ideahow to add include_type_name parameter is set to true in node.js/mongoosastic
This is my code
var model_catagories = "products";
productsSchema.plugin(mongoosastic);
// Export Contact model
var Products = module.exports = mongoose.model(model_catagories, productsSchema);
Products.createMapping({ include_type_name: true }, function(err, mapping) {
if (err) {
console.log('error creating mapping (you can safely ignore this)');
console.log(err);
} else {
console.log('mapping created!');
console.log(mapping);
}
});
I have use code for https://github.com/mongoosastic/mongoosastic/blob/master/example/blog/app.js hear. I'm new in node.js, MongoDB, elasticsearch.
I have a database of MongoDB I'm trying to Mapping with elasticsearch. I want to join both if it adds data in MongoDB on then it will automatically add on elasticsearch DB. I want to only search data using elasticsearch otherwise i will use MongoDB.
回答1:
I don't think you could add parameter directly to the typeName. If you check the code from elasticsearch javascript client, you would find that it encode your typename to escape from those URI chars: Link here. Your ?
in the parameter would be encoded such that it would be part of the type.
I have not verified this, but reading code from elasticsearch-js put mapping function, I think you might want to try this:
...
return client.indices.putMapping({
index: indexName,
type: typeName,
body: completeMapping,
includeTypeName: true // Add parameter for your put mapping.
}, (err) => {
cb(err, completeMapping[typeName])
})
...
来源:https://stackoverflow.com/questions/57325097/include-type-name-parameter-is-set-to-true-in-node-js