Mongoosastic:按距离排序错误

时间:2015-10-06 03:18:20

标签: elasticsearch mongoosastic

当我尝试按照与Mongoosastic的距离对搜索结果进行排序时,我收到以下弹性搜索错误:

  

{message:' SearchPhaseExecutionException [无法执行阶段   [query_fetch],所有分片都失败了; shardFailures   {[rQFD7Be9QbWIfTqTkrTL7A] [users] [0]:SearchParseException [[users] [0]:   查询[滤波(+关键字:咖啡馆) - > GeoDistanceFilter(位置,   SLOPPY_ARC,25000.0,-70.0264952,41.2708115)],从[-1],大小[-1]:   解析失败[无法解析源代码   [{" timeout":60000," sort":[{" [object Object]":{}}]}]]];嵌套:   SearchParseException [[用户] [0]:   查询[滤波(+关键字:咖啡馆) - > GeoDistanceFilter(位置,   SLOPPY_ARC,25000.0,-70.0264952,41.2708115)],从[-1],大小[-1]:   解析失败[找不到[[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},
});

1 个答案:

答案 0 :(得分:0)

我也遇到了错误,我认为Mongoosastic的升级是双重包装代码。它似乎是基于&#39; sort&#39;而不是搜索,但仍在审查。 Val似乎对正在发生的事情有了更好的了解,因为它可能与用户架构而不是功能有关。

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