Package org.elasticsearch.script

Examples of org.elasticsearch.script.ExecutableScript.run()


    params.put(ProcessConstants.ES_PLUGIN_LISTUPDATE_ID_FIELD, "key");
    params.put(ProcessConstants.ES_PLUGIN_LISTUPDATE_ID_VALUE, "2");
    params.put(ProcessConstants.ES_PLUGIN_LISTUPDATE_VALUE, mapOf("key", "2", "value", "B"));
    script = factory.newScript(params);
    script.setNextVar("ctx", ImmutableMap.of("_source", source));
    script.run();
    mapFields = (Collection) source.get(listField);
    assertThat(mapFields).hasSize(2);

    // updated first item in list
    params = new HashMap<String, Object>();
View Full Code Here


    params.put(ProcessConstants.ES_PLUGIN_LISTUPDATE_ID_FIELD, "key");
    params.put(ProcessConstants.ES_PLUGIN_LISTUPDATE_ID_VALUE, "1");
    params.put(ProcessConstants.ES_PLUGIN_LISTUPDATE_VALUE, mapOf("key", "1", "value", "a"));
    script = factory.newScript(params);
    script.setNextVar("ctx", ImmutableMap.of("_source", source));
    script.run();
    mapFields = (Collection) source.get(listField);
    assertThat(mapFields).hasSize(2);

    // updated second item in list
    params = new HashMap<String, Object>();
View Full Code Here

    params.put(ProcessConstants.ES_PLUGIN_LISTUPDATE_ID_FIELD, "key");
    params.put(ProcessConstants.ES_PLUGIN_LISTUPDATE_ID_VALUE, "2");
    params.put(ProcessConstants.ES_PLUGIN_LISTUPDATE_VALUE, mapOf("key", "2", "value", "b"));
    script = factory.newScript(params);
    script.setNextVar("ctx", ImmutableMap.of("_source", source));
    script.run();
    mapFields = (Collection) source.get(listField);
    assertThat(mapFields).hasSize(2);

    // delete first item
    params = new HashMap<String, Object>();
View Full Code Here

    params.put(ProcessConstants.ES_PLUGIN_LISTUPDATE_ID_FIELD, "key");
    params.put(ProcessConstants.ES_PLUGIN_LISTUPDATE_ID_VALUE, "1");
    params.put(ProcessConstants.ES_PLUGIN_LISTUPDATE_VALUE, null);
    script = factory.newScript(params);
    script.setNextVar("ctx", ImmutableMap.of("_source", source));
    script.run();
    mapFields = (Collection) source.get(listField);
    assertThat(mapFields).hasSize(1);
  }

  private Map<String, Object> mapOf(String k, String v, String k1, String v1) {
View Full Code Here

                        Map<String, Object> vars = new HashMap<String, Object>();
                        vars.put("x", x);
                        vars.put("y", y);
                        ExecutableScript script = se.executable(compiled, vars);
                        for (int i = 0; i < 100000; i++) {
                            long result = ((Number) script.run()).longValue();
                            assertThat(result, equalTo(addition));
                        }
                    } catch (Throwable t) {
                        failed.set(true);
                        logger.error("failed", t);
View Full Code Here

                        ExecutableScript script = se.executable(compiled, vars);
                        for (int i = 0; i < 100000; i++) {
                            long y = ThreadLocalRandom.current().nextInt();
                            long addition = x + y;
                            script.setNextVar("y", y);
                            long result = ((Number) script.run()).longValue();
                            assertThat(result, equalTo(addition));
                        }
                    } catch (Throwable t) {
                        failed.set(true);
                        logger.error("failed", t);
View Full Code Here

        ctx.put("doc", doc);

        Object complied = se.compile("ctx.doc.field1 = ['value1', 'value2']");
        ExecutableScript script = se.executable(complied, new HashMap<String, Object>());
        script.setNextVar("ctx", ctx);
        script.run();

        Map<String, Object> unwrap = (Map<String, Object>) script.unwrap(ctx);

        assertThat(((Map) unwrap.get("doc")).get("field1"), instanceOf(List.class));
    }
View Full Code Here

        vars.put("ctx", ctx);
        Object compiledScript = se.compile("ctx.value");

        ExecutableScript script = se.executable(compiledScript, vars);
        ctx.put("value", 1);
        Object o = script.run();
        assertThat(((Number) o).intValue(), equalTo(1));

        ctx.put("value", 2);
        o = script.run();
        assertThat(((Number) o).intValue(), equalTo(2));
View Full Code Here

        ctx.put("value", 1);
        Object o = script.run();
        assertThat(((Number) o).intValue(), equalTo(1));

        ctx.put("value", 2);
        o = script.run();
        assertThat(((Number) o).intValue(), equalTo(2));
    }

    @Test
    public void testChangingVarsCrossExecution2() {
View Full Code Here

        Map<String, Object> vars = new HashMap<String, Object>();
        Object compiledScript = se.compile("value");

        ExecutableScript script = se.executable(compiledScript, vars);
        script.setNextVar("value", 1);
        Object o = script.run();
        assertThat(((Number) o).intValue(), equalTo(1));

        script.setNextVar("value", 2);
        o = script.run();
        assertThat(((Number) o).intValue(), equalTo(2));
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.