matteodem / meteor-easy-search

Easy-to-use search for Meteor with Blaze Components
MIT License
438 stars 68 forks source link

Filter by category with Elastic Search: Malformed query error #619

Closed programthis closed 2 years ago

programthis commented 6 years ago

I am attempting to filter a search result by a certain category with the elastic search package by am met with a malformed query error:

[Error: [parsing_exception] [bool] malformed query, expected [END_OBJECT] but found [FIELD_NAME]

Here is my code (I suspect the query result is not formatted correctly):

export const QuestionsIndex = new Index({
    collection: Questions,
    fields: ["title", "description"],
    engine: new ElasticSearchEngine({
        body: function(body, opts) {
            return {
                query: body.query,
                stored_fields: body.fields
            }
        },
        query: function(searchObject, options, aggregation) {
            let query = this.defaultConfiguration().query(searchObject, options, aggregation),
                category = options.search.props.category;
            if (_.isString(category) && !_.isEmpty(category)) {
                query["category"] = category;
            }           
            return query;
        }
    })
});

I would like to note that I have been following issues previously raised on this topic (such as this one that ultimately recommended mapping) but have not found a solution. Is there an example that I could follow for this particular functionality?

matteodem commented 2 years ago

This seems to be an ElasticSearch error and not one connected to the functionality of this library.