All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.greencheek.related.plugins.relateddocsmerger.RelatedDocsMergerScript Maven / Gradle / Ivy

Go to download

Related Content Document Merging Plugin that updates related document based on if the content has changed or not.

The newest version!
package org.greencheek.related.plugins.relateddocsmerger;

import org.elasticsearch.script.AbstractExecutableScript;

import java.util.Map;


public class RelatedDocsMergerScript extends AbstractExecutableScript {

    private final Map params;
    private Map ctx;
    private Map source;
    final String comparatorValue;
    final String comparatorKey;

    RelatedDocsMergerScript(Map params,
                            String comparatorKey,
                            String comparatorValue) {
        this.params = params;
        this.comparatorKey = comparatorKey;
        this.comparatorValue = comparatorValue;
    }

    @Override
    public void setNextVar(String name, Object value) {
        if(name.equals("ctx") && value instanceof Map) {
            ctx = (Map )value;
            source = (Map)ctx.get("_source");
        }
    }

    @Override
    public Object run() {
        if(ctx==null || source==null || comparatorValue == null || params==null) {
            return null;
        }

        String md5Prop = (String) source.get(comparatorKey);
        if (md5Prop == null) {
            for (String key : params.keySet()) {
                source.put(key, params.get(key));
            }
        } else {
            if (md5Prop.equals(comparatorValue)) {
                ctx.put("op", "none");
            } else {
                for (String key : params.keySet()) {
                    source.put(key, params.get(key));
                }
            }
        }

        return null;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy