0

我正在尝试使用elasticsearch facet script,但是当我进入 reduce 阶段的 NativeScriptFactory 时,传递的 map 参数为空。这是我的查询:

    "facets": {
    "myFacet": {
        "script": {
            "lang": "native",
            "map_script": "MyMap",            
            "reduce_script": "MyReduce",            
            "params" : {
                "facet" : {}
            }        
        }
    }
}

当我使用默认减速器时,我得到以下响应:

   "facets": {
        "myFacet": {
            "_type": "script",
            "facet": [
                {
                    "222790": 7,
                    "762984": 7
                }
            ]
        }
    }

我的地图脚本如下所示:

public class MyMapScript extends AbstractSearchScript {

    private Map<String, Double> _myScores;

    public MyMapScript(Map<String, Object> stringObjectMap) {

        _myScores = (Map<String, Double>) stringObjectMap.get("facet");
    }

    @Override
    public Object run() {
        ScriptDocValues.NumericLong tags = (ScriptDocValues.NumericLong) doc().get("tags");
        for (Long t : tags.getValues()){
            Double score = 7.0;
            _myScores.put(t.toString(), score);
        }

        return _myScores;
    }
}

和 reduce 脚本工厂,它获取一个空映射作为参数:

public class MyReduceScriptFactory implements NativeScriptFactory {
    @Override
    public ExecutableScript newScript(@Nullable Map<String, Object> stringObjectMap) {
        return new MyReduceScript(stringObjectMap);
    }
}

我该怎么做才能将映射器的输出传递给减速器?

4

1 回答 1

0

显然这是在最新版本中修复的,我使用的是旧版本。

于 2013-09-23T09:18:52.793 回答