I am trying to index only the 'particulars' field of boqEntry into an Elasticsearch instance using Mongoosastic and later query them. 'boqList' inside BOQ comprises of boqEntries. I have defined my schema as described in the code below. I am indexing my BOQ document after uploading them via FilePond. Whenever I perform the query (http://localhost:9200/boqss/boqs/_search) onto Elasticsearch.
I get a response like this :
"hits": [
{
"_index": "boqss",
"_type": "boqs",
"_id": "5d9730d83f756d04a8d6dbfe",
"_score": 1.0,
"_source": {
"projectId": "5d860711cf3b052a34a84f6c",
"boqList": [
{
"particulars": "Excavation "
},
{
"particulars": "Providing & laying Rubble Soling"
},
{
"particulars": "Providing & laying PCC M10"
},
{
"particulars": "Providing & Laying Reinforcement With Cutting, Bending & Binding With Binding Wire Etc Complete."
},
{
"particulars": "Providing & Making Double Scaffolding"
},
{
"particulars": "Providing & Casting R.C.C M25"
},
{
"particulars": "Providing & Applying Cement Plaster"
},
...
However I want to be able to retrieve only those specific 'particulars' from the boqList array that match a searchTerm from my search box that I am implementing in my React based front-end, like a full text search. I am relatively new to the MERN stack, Mongoose and Elasticsearch. I would really appreciate any help. Thank you !!
Here is the mongoose schema :
const mongoose = require('mongoose')
const Schema = mongoose.Schema
var mongoosastic = require('mongoosastic')
const boqEntry = new Schema({
particulars : {type : String, es_indexed : true},
quantity : {type : Number},
unit : {type : String},
rate : {type : Number},
amount : {type : Number},
});
const BOQ = new Schema(
{
projectId : { type : String},
boqList : {type : [boqEntry], es_type : 'nested'}
},
{ timestamps: true },
);
BOQ.plugin(mongoosastic)
module.exports = mongoose.model('boqs', BOQ)