Algolia is receiving the queries but unable to get the response search results

I am building an application with NodeJS and MongoDB in the backend and for searching and sorting I am using Algolia. But everytime I search using query, the query is received by algolia and records it but doesnot responds back with result. I don’t know why the response is not being sent back. I’ll present my code below:

const router = require('express').Router();
const algoliasearch = require('algoliasearch');

const client = algoliasearch('XXXXXXXXX', 'XXXX.......XXXXX');
const index = client.initIndex('XXXXXXX');

router.get('/',(req, res, next) => {
  if (req.query.query) {
     index.search({
          query: req.query.query,
          page: req.query.page,
     }, ( err, content) => {
       if (err) {
         return err;
       } else {
         res.json({
             success: true,
             message: "Here is your search result",
             status: 200,
             content: content,
             search_result: req.query.query
         });
       }
     }).then(({ hits }) => {
       console.log(hits);
  })
 }else { res.json({
     success: false,
     message : "please enter search term",
  });
  }
});
module.exports = router;

The above mentioned block of code is what I have used in my route file, product-search.js. The route file should be receiving GET response but instead Algolia receives POST method and status: 200 but fails to return the search result.

Here is the image from my search Analytics:

And the Search Log displays the following API Call details:

Is it not reading the searchable attribute?? or did I made an newbie error in coding.

I have Set and Sync To Algolia in my model file using the following set of codes inside my product model file product.js :

const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const mongooseAlgolia = require('mongoose-algolia');

const ProductSchema = new Schema({

    category: { type: Schema.Types.ObjectId, ref: 'Category' },
    owner: { type: Schema.Types.ObjectId, ref: 'User'},
    reviews: [{ type: Schema.Types.ObjectId, ref: 'Review' }],
    image: String,
    title: String,
    description: String,
    price: Number,
    created: { type: Date, default: Date.now }
}, { 
    toObject: { virtuals: true },
    toJSON: { virtuals:true }
});

ProductSchema.plugin(mongooseAlgolia, {

    appId: 'XXXXXXXX',
    apiKey: 'XXXXXX.......XXXXxX',
    indexName: 'XXXXXXXX',
 
   selector: '_id title image description reviews price owner created averageRating',
    populate: {
        path: 'owner reviews',
        select: 'name rating'
    },
    defaults: {
        author: 'unknown'
    },
    mappings: {
        title: function(value) {
            return `${value}`;
        },
    },
    virtuals: {
        averageRating: function(doc) {
            var rating = 0;
        if (doc.reviews.length == 0) {
            rating = 0;
        } else {
            doc.reviews.map((review) => {
                rating += review.rating;
            });
            rating = rating / doc.reviews.length;
        }
        return rating;
        },
    },
    filter: function(doc) {
        return !doc.softdelete
    },
    debug: true
})
let Model = mongoose.model('Product', ProductSchema);
Model.SyncToAlgolia();
Model.SetAlgoliaSettings({
    searchableAttributes: ['title']
})
module.exports = Model

I am hopeful in getting the positive response. Thanks in advance.

Hey there,

I’m Dorian, software engineer at Algolia.

May I ask where the SyncToAlgolia and SetAlgoliaSettings come from? Have you implemented them yourself?

By default, we have a limited view of your application. Since your question requires us to access your index configuration and records, would you mind granting us access to your application?

Please head over to the Algolia support access page to provide us with at least 7 days or more of read access. When you have completed this step, please confirm by sending us an email at support@algolia.com .

Thanks in advance!

Hello Dorian,

Thank you for your reply. I think I have uploaded the wrong screenshot for the API Call Detail. I will edit the issue. And The SyncToAlgolia() and SetAlgoliaSetting () are the functions used in my Model file i.e. product,js.i will submit the code of my model in the issue. I have also provided the read access to my application to Algolia.

I hope the Algolia support team will review it and help to solve this issue.

Thank you.

Hi,
I hope you have your support team has got my email and I am hopefully looking forward on fixing the issue.

Thank you again.

Hi @roshansharma139, I’m not finding your email. Could you try to send the email to support again?