0

当我尝试使用 Mongoosastic 按距离对搜索结果进行排序时,出现以下 Elastic Search 错误:

{ message: 'SearchPhaseExecutionException [未能执行阶段 [query_fetch],所有分片失败;shardFailures {[rQFD7Be9QbWIfTqTkrTL7A][users][0]: SearchParseException[[users][0]: query[filtered(+keywords:cafe)->GeoDistanceFilter(location, SLOPPY_ARC, 25000.0, -70.0264952, 41.2708115)],from[- 1],size[-1]: 解析失败[解析源失败[{"timeout":60000,"sort":[{"[object Object]":{}}]}]]]; 嵌套:SearchParseException[[users][0]: query[filtered(+keywords:cafe)->GeoDistanceFilter(location, SLOPPY_ARC, 25000.0, -70.0264952, 41.2708115)],from[-1],size[-1]: Parse失败 [未找到 [[object Object]] 的映射以便排序]];}]' }

代码示例见下文:

var query = {
    "filtered": {
        "query": {
            "bool": {
                "must": [
                    {
                        "term": {
                            "keywords": "cafe"
                        }
                    }
                ]
            }
        },
        "filter": {
            "geo_distance": {
                "distance": "25km",
                "location": [
                    41.2708115,
                    -70.0264952
                ]
            }
        }
    }
};

var opts = {
    "sort": [
        {
            "_geo_distance": {
                "location": [
                    41.2708115,
                    -70.0264952
                ],
                "order":         "asc",
                "unit":          "km",
                "distance_type": "plane"
            }
        }
    ],
    "script_fields": {
        "distance": "doc[\u0027location\u0027].distanceInMiles(41.2708115, -70.0264952)"
    }
};

User.search(query, opts, function (err, data) {
    if (err || !data || !data.hits || !data.hits.hits || !data.hits.hits.length) {
        return callback(err);
    }

    var total = data.hits.total,
    //page = params.page || 1,
        per_page = query.size,
        from = query.from,
    //to = from +
        page = query.from / query.size,
        rows = data.hits.hits || [];
    for (var i = 0; i < rows.length; i++) {
        rows[i].rowsTotal = total;
    }
    callback(err, toUser(rows, params));
});

这是用户模式:

var schema = new Schema({
    name: {type: String, default: '', index: true, es_type: 'string', es_indexed: true},
    location: {type: [Number], es_type: 'geo_point', es_indexed: true, index: true},
    shareLocation: {type: Boolean, default: false,  es_type: 'boolean', es_indexed: true},
    lastLocationSharedAt: {type: Date},
    email: {type: String, default: '', index: true, es_type: 'string', es_indexed: true},
    birthday: {type: String, default: ''},
    first_name: {type: String, default: ''},
    last_name: {type: String, default: ''},
    gender: {type: String, default: ''},
    website: {type: String, default: '', index: true, es_indexed: true},
    verified: {type: Boolean, default: false},
});
4

1 回答 1

0

我也遇到了一个错误,我认为 Mongoosastic 的升级是双重包装代码。它似乎是基于“排序”而不是基于搜索但仍在审查。Val 似乎对正在发生的事情有更好的了解,因为它可能与用户模式而不是功能有关。

我正在使用类似的架构,只是升级并遇到了问题。

于 2015-10-06T21:49:54.100 回答