jbdemonte / mongoose-elasticsearch-xp

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

Populate is not working and the value is ignored #64

Open binfask opened 4 years ago

binfask commented 4 years ago

when i am adding es_type in model the value is ignored from indexing I have two models category and products in that i need to populate the primarycategoryid. Category schema

import { Schema, model } from "mongoose";
var mexp = require('mongoose-elasticsearch-xp').v7;

var categorySchema = Schema({
    title: {
        type: String,
        required: 'title required',
        trim: true
    },
    description: {
        type: String,
        trim: true
    },
    imageurl: {
        type: String
    }
})

categorySchema.plugin(mexp);

// Export Category
var categoryModel = (module.exports = model("category", categorySchema));

Product Schema

 import { Schema, model, } from "mongoose";
 var mexp = require('mongoose-elasticsearch-xp').v7;

 var productSchema = Schema({
   productname: {
     type: String,
     required: "Product name required",
     trim: true
   },
   description: {
     type: String,
     required: "Description required",
     trim: true
   },
   shortdescription: {
     type: String,
     trim: true
   },
   pricing: [
     {
       baseprice: {
         required: "Price required",
         type: Number,
         trim: true
       },
       offerprice: {
         required: "Price required",
         type: Number,
         trim: true
       }
     }
   ],
   primarycategoryid: {
     type: Schema.Types.ObjectId,
     required: "Primary Category id",
     ref: 'category',
     es_type: {
       title: {
         es_type: 'string'
       }
     }
   },
   thumbnailurl: {
     type: String
   },
 });

 productSchema.plugin(mexp);

 // Export product
 var productModel = (module.exports = model("product", productSchema));

But in elastic search the primarycategoryid is not there, when i am removing

es_type: { title: { es_type: 'text' } }

the primarycategoryid added