I have set of products indexed in elasticsearch. I`m searching for "title" on my schema. When I search "fre" or "fresh" I see a result. But when I search for "small fresh" I don't see any result. Is it possible to use wildcard with spaces ? I added es_indexed: "not_analyzed" but no luck.
This is my Product Schema
const mongoose = require("mongoose");
const Schema = mongoose.Schema;
var mongoosastic = require("mongoosastic");
const deepPopulate = require("mongoose-deep-populate")(mongoose);
var Owner = require("./user");
var Category = require("./category");
var Reviews = require("./review");
const ProductSchema = new Schema(
{
category: {
type: Schema.Types.ObjectId,
ref: "Category",
es_indexed: true,
es_type: "nested",
es_include_in_parent: true
},
owner: {
type: Schema.Types.ObjectId,
ref: "User",
es_indexed: true,
es_type: "nested",
es_include_in_parent: true
},
reviews: [
{
type: Schema.Types.ObjectId,
ref: "Review",
es_indexed: true,
es_type: "nested",
es_include_in_parent: true
}
],
image: { type: String, es_indexed: true },
title: {
type: String,
es_indexed: "not_analyzed"
},
description: { type: String, es_indexed: true },
price: { type: Number, es_indexed: true },
crated: { type: Date, default: Date.now, es_indexed: true }
},
{
toObject: { virtuals: true },
toJSON: { virtuals: true }
}
);
ProductSchema.virtual("averageRating").get(function() {
var rating = 0;
if (this.reviews.length == 0) {
rating = 0;
} else {
this.reviews.map(review => {
rating += review.rating;
});
rating = rating / this.reviews.length;
}
return rating;
});
ProductSchema.plugin(deepPopulate);
ProductSchema.plugin(mongoosastic, {
populate: [{ path: "category" }, { path: "owner" }, { path: "reviews" }]
});
let Model = mongoose.model("Product", ProductSchema);
Model.createMapping(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);
}
});
var stream = Model.synchronize();
var count = 0;
stream.on("data", (err, doc) => {
console.log(doc);
count++;
});
stream.on("close", () => console.log("indexed " + count + " documents!"));
stream.on("error", err => console.log(err));
Model.SyncToAlgolia();
Model.SetAlgoliaSettings({
searchableAttributes: ["title"]
});
module.exports = Model;
This is my Search function
async function search(frompage) {
let fullString = "*" + "small fresh" + "*";
let startsFrom = frompage * 10;
console.log(fullString);
const response = await esClient.search({
index: "products",
type: "product",
from: startsFrom,
body: {
query: {
wildcard: {
title: fullString
}
}
}
});
return response;
}