将参数传递给ElasticSearch构面脚本的本机reduce脚本

时间:2013-09-23 07:51:45

标签: mapreduce elasticsearch

我正在尝试使用elasticsearch facet script,但是当我到达reduce阶段的NativeScriptFactory时,传递的map参数为空。 这是我的疑问:

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

当我使用默认的reducer时,我得到了这个回复:

   "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);
    }
}

我需要做些什么才能将映射器输出到reducer?

1 个答案:

答案 0 :(得分:0)

显然这是在latest version修复的,我使用的是较旧版本。