jbdemonte / mongoose-elasticsearch-xp

A mongoose plugin that indexes models into Elasticsearch 2 / 5 / 6 and 7
93 stars 34 forks source link

[Bag] TypeError: Cannot read property 'toLowerCase' of undefined #79

Open IlyaShkurenko opened 3 years ago

IlyaShkurenko commented 3 years ago
require('mongoose-double')(mongoose);

const Schema = mongoose.Schema;
const Double = Schema.Types.Double;

const productSchema = new Schema(
  {
    isCloseout: { type: Boolean, required: true, index: true, default: false },
    isCaution: { type: Boolean, required: true, index: true, default: false },
    isOnDemand: { type: Boolean, required: true, index: true, default: false },
    isHazmat: { type: Boolean, required: true, index: true, default: false },
    productId: { type: String, required: true, index: true, es_indexed: true, es_type: 'text' },
    productName: { type: String, required: true, index: true, es_indexed: true, es_type: 'text' },
    slug: { type: String, required: true, index: true, unique: true, es_indexed: true, es_type: 'keyword' },,
    priceMax: { type: Double, index: true },
    priceMin: { type: Double, index: true },
    status: { type: String, index: true, es_indexed: true, es_type: 'text' }
  },
  { timestamps: true }
);

there is error in function because It can't detect Double type instance for field priceMax and priceMin even if it's not marked as es_index: true

module.exports.getType = function getType(path) {
  return (path.caster && path.caster.instance
    ? path.caster.instance
    : path.instance
  ).toLowerCase();
};