使用 mongoosastic 进行 Elasticsearch 查询

Elasticsearch query with mongoosastic

我正在尝试这样查询:

Gym.search({
                    "query" : {
                        "multi_match": {
                            "fields": ["multi_field"],
                            "query": req.query.q,
                            "fuzziness": "AUTO"
                        }
                    }
                },
                function (err, results) {
                    if (err) {
                        return console.log(JSON.stringify(err, null, 4));
                    }
                    return console.log(JSON.stringify(results, null, 4));
                });

但是 returns:

"status": 400, "displayName": "BadRequest", "message": "SearchPhaseExecutionException[Failed to execute phase [query], all shards failed; shardFailures {[PzLsLPHfTMu68AQ94_Af8g][gyms][0]: SearchParseException[[gyms][0]: from[-1],size[-1]: Parse Failure [Failed to parse source [{\"query\":{\"query\":{\"multi_match\":{\"fields\":[\"multi_field\"],\"query\":\"LCC\",\"fuzziness\":\"AUTO\"}}}}]]]; nested: QueryParsingException[[gyms] No query registered for [query]]; }{[PzLsLPHfTMu68AQ94_Af8g][gyms][1]: SearchParseException[[gyms][1]: from[-1],size[-1]: Parse Failure [Failed to parse source [{\"query\":{\"query\":{\"multi_match\":{\"fields\":[\"multi_field\"],\"query\":\"LCC\",\"fuzziness\":\"AUTO\"}}}}]]]; nested: QueryParsingException[[gyms] No query registered for [query]]; }{[PzLsLPHfTMu68AQ94_Af8g][gyms][2]: SearchParseException[[gyms][2]: from[-1],size[-1]: Parse Failure [Failed to parse source [{\"query\":{\"query\":{\"multi_match\":{\"fields\":[\"multi_field\"],\"query\":\"LCC\",\"fuzziness\":\"AUTO\"}}}}]]]; nested: QueryParsingException[[gyms] No query registered for [query]]; }{[PzLsLPHfTMu68AQ94_Af8g][gyms][3]: SearchParseException[[gyms][3]: from[-1],size[-1]: Parse Failure [Failed to parse source [{\"query\":{\"query\":{\"multi_match\":{\"fields\":[\"multi_field\"],\"query\":\"LCC\",\"fuzziness\":\"AUTO\"}}}}]]]; nested: QueryParsingException[[gyms] No query registered for [query]]; }{[PzLsLPHfTMu68AQ94_Af8g][gyms][4]: SearchParseException[[gyms][4]: from[-1],size[-1]: Parse Failure [Failed to parse source [{\"query\":{\"query\":{\"multi_match\":{\"fields\":[\"multi_field\"],\"query\":\"LCC\",\"fuzziness\":\"AUTO\"}}}}]]]; nested: QueryParsingException[[gyms] No query registered for [query]]; }]"

当我使用 CURL 时它有效...有人知道如何修复它吗?

这样试试:

 Gym.search({
                "multi_match": {
                    "fields": ["multi_field"],
                    "query": req.query.q,
                    "fuzziness": "AUTO"
                }
            },
            function (err, results) {
                if (err) {
                    return console.log(JSON.stringify(err, null, 4));
                }
                return console.log(JSON.stringify(results, null, 4));
            });