Code Monkey home page Code Monkey logo

elasticsearch-lang-javascript's Introduction

IMPORTANT: Project MOVED!

From elasticsearch 2.0 you need to look at the following links:

For older versions, look at the following documentation.

In order to install the plugin, run:

bin/plugin install elasticsearch/elasticsearch-lang-javascript/VERSION

Where VERSION is the one you want to install.

elasticsearch JavaScript Plugin Docs
master Build from source See below
es-1.7 2.7.0 2.7.0
es-1.6 2.6.0 2.6.0
es-1.5 2.5.0 2.5.0
es-1.4 2.4.1 2.4.1
es-1.3 2.3.1 2.3.1
es-1.2 2.2.0 2.2.0
es-1.1 2.1.0 2.1.0
es-1.0 2.0.0 2.0.0
es-0.90 1.4.0 1.4.0

License

This software is licensed under the Apache 2 license, quoted below.

Copyright 2009-2014 Elasticsearch <http://www.elasticsearch.org>

Licensed under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy of
the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations under
the License.

elasticsearch-lang-javascript's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

elasticsearch-lang-javascript's Issues

indices.putTemplate() creates empty legacy index template!?

Given:

esClient.indices.putTemplate({name:"events.location", body: {
	index_patterns: ['*.events'],
  template: {
    mappings: {
      properties: {
        location: {
          properties: {
            coordinates: {
              type: "geo_point",
              ignore_malformed: false,
              ignore_z_value: true
            }
          }
        }
      }
    }
  }
}})

For some reason this results in a empty legacy index template.

Unable to install js plugin in ES 2.0

I get this error when installing

NOTE: Unable to verify checksum for downloaded plugin (unable to find .sha1 or .md5 file to verify)
ERROR: Could not find plugin descriptor 'plugin-descriptor.properties' in plugin zip

checked the jar, it has es-plugin.properties file instead of plugin-descriptor.properties, is there some way to get it working

Unable to mvn clean install off the es-1.5 branch

I'm trying to build the plugin from source and am getting this issue:

mvn clean install -U -DskipTests

Results in the below

[INFO] Scanning for projects...
Downloading: https://oss.sonatype.org/content/repositories/snapshots/org/elasticsearch/elasticsearch-parent/1.5.0-SNAPSHOT/maven-metadata.xml
Downloading: https://oss.sonatype.org/content/repositories/snapshots/org/elasticsearch/elasticsearch-parent/1.5.0-SNAPSHOT/elasticsearch-parent-1.5.0-SNAPSHOT.pom
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[FATAL] Non-resolvable parent POM for org.elasticsearch:elasticsearch-lang-javascript:2.5.0-SNAPSHOT: Could not find artifact org.elasticsearch:elasticsearch-parent:pom:1.5.0-SNAPSHOT in oss-snapshots (https://oss.sonatype.org/content/repositories/snapshots/) and 'parent.relativePath' points at wrong local POM @ line 7, column 13
@
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]
[ERROR] The project org.elasticsearch:elasticsearch-lang-javascript:2.5.0-SNAPSHOT (/Users/tim/Projects/thirdparty/elasticsearch-lang-javascript/pom.xml) has 1 error
[ERROR] Non-resolvable parent POM for org.elasticsearch:elasticsearch-lang-javascript:2.5.0-SNAPSHOT: Could not find artifact org.elasticsearch:elasticsearch-parent:pom:1.5.0-SNAPSHOT in oss-snapshots (https://oss.sonatype.org/content/repositories/snapshots/) and 'parent.relativePath' points at wrong local POM @ line 7, column 13 -> [Help 2]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException
[ERROR] [Help 2] http://cwiki.apache.org/confluence/display/MAVEN/UnresolvableModelException

JavaScript string constant is not treated as string in 1.4.0

I have one script filter as below, which just functions as to delete document fields except "work".

{
 "script":"if(ctx.document.work) { for(var key in ctx.document) { if(key=='work')) { delete ctx.document[key]; } } }"
}

However, it doesn't behaves as expected. I checked it with head plugin. It turns out that the script is saved as below. The string constant "work" is saved as variable "work".

if(ctx.document.work) { for(var key in ctx.document) { if(key==work)) { delete ctx.document[key]; } } }

As a result, I work around by utilizing regular expression.

 "script":"if(ctx.document.work) { for(var key in ctx.document) { if(!/^work$/.test(key)) { delete ctx.document[key]; } } }"

Is this a known issue?
Is string constant not supported?

Use of javascript in mapping `transform` fails

Below reproduction shows that while it is possible to use groovy in mapping transform the same operation fails when javascript is used.

Tested with Elasticsearch 1.4.1, 1.4.4 and 1.5.0.

Reproduction

Download fresh Elasticsearch (1.4.1) and install lang-javascript plugin (2.4.1):

wget https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.4.1.zip
unzip elasticsearch-1.4.1.zip
cd elasticsearch-1.4.1
./bin/plugin install elasticsearch/elasticsearch-lang-javascript/2.4.1

Enable scripting:

echo script.disable_dynamic: false | tee -a config/elasticsearch.yml > /dev/null
cat config/elasticsearch.yml | grep script
# script.disable_dynamic: false

Start node:

./bin/elasticsearch -d

After node is ready check we have a fresh empty cluster with javascript plugin only:

curl 'http://localhost:9200/_cat/health?v'
# epoch      timestamp cluster       status node.total node.data shards pri relo init unassign 
#1427789340 10:09:00  elasticsearch green           1         1      0   0    0    0        0 

curl 'localhost:9200/_cat/plugins?v'
# name      component       version type url
# Maur-Konn lang-javascript 2.4.1   j

Create index with transform script:

curl -X PUT 'localhost:9200/test_javascript' -d '{
  "mappings": {
    "test": {
      "transform": {
        "script":"true",
        "lang": "javascript"
      }
    }
  }
}'
# {"acknowledged":true}

curl -X PUT 'localhost:9200/test_groovy' -d '{
  "mappings": {
    "test": {
      "transform": {
        "script":"true",
        "lang": "groovy"
      }
    }
  }
}'
# {"acknowledged":true}

curl -X GET 'localhost:9200/test*/_mapping?pretty'
#{
#  "test_groovy" : {
#    "mappings" : {
#      "test" : {
#        "transform" : {
#          "script" : "true",
#          "lang" : "groovy"
#        },
#        "properties" : { }
#      }
#    }
#  },
#  "test_javascript" : {
#    "mappings" : {
#      "test" : {
#        "transform" : {
#          "script" : "true",
#          "lang" : "javascript"
#        },
#        "properties" : { }
#      }
#    }
#  }
#}

Index document into test indices:

curl -X POST 'localhost:9200/test_groovy/test' -d '{ "foo": "bar" }'
# {"_index":"test_groovy","_type":"test","_id":"AUxu4fLdiRC7ona2R0WV","_version":1,"created":true}

curl -X POST 'localhost:9200/test_javascript/test' -d '{ "foo": "bar" }'
# {"error":"MapperParsingException[failed to parse]; nested: ElasticsearchIllegalArgumentException[failed to execute script]; nested: NullPointerException; ","status":400}

elastic/elasticsearch#10336

How to access logger from lang-javascript

I have just started using lang-javascript for calculating a custom score, and want to debug the script I have written. I checked out the following links:

https://groups.google.com/forum/#!searchin/elasticsearch/javascript$20log/elasticsearch/NwTjyJ35ZoU/ffEPiJq_K0QJ
https://groups.google.com/forum/#!searchin/elasticsearch/javascript$20log/elasticsearch/wwaaWsKZ7Nw/sVpEqV2Mi3YJ

and searched through elasticsearch documentation but am unable to figure out how to log from within the lang-javascript script.

Is there a way to log from the lang-javascript scripts?

Rhino usage warning: Missed Context.javaToJS() conversion

I'm using a JS script to process some properties on upsert. It appears that when the param passed to the script is a JS object containing other objects, those objects are not properly converted to JS types, and Rhino throws a warning in the elasticsearch log:

RHINO USAGE WARNING: Missed Context.javaToJS() conversion:
Rhino runtime detected object { /** lots of properties here **/ } of class java.util.LinkedHashMap where it expected String, Number, Boolean or Scriptable instance. Please check your code for missing Context.javaToJS() call.

When enumerating nested objects in the script, they are not proper JS objects:

// throws exception
typeof ctx._source.anObject.anotherobject;

// using a custom typeof function...
var typeOf = function(v) {
  return (
    Object.prototype.toString.call(v).match(/\[object ([A-Za-z]+)\]/)[1].toLowerCase()
  );
};

typeOf(ctx._source.anObject.anotherobject); // returns 'nativemap'
typeOf(ctx._source.anObject.anArray); // returns 'nativelist'

I can convert to proper JS types by iterating the objects and copying the properties / values, but surely these should be converted when passing the doc source and script params to the scope? Might be related to the Rhino warning.

[Test] tests broken with es 2.0.0-SNAPSHOT and seed 2A366D601264C712

Tests don't pass anymore with elasticsearch master branch (2.0.0-SNAPSHOT):

Tests that seem to be affected:

  • testCustomScriptBoost : systematic failure with seed 2A366D601264C712
  • testScriptScoresNested : sporadic failure
  • testScriptScoresWithAgg : sporadic failure
mvn clean test -Dtests.seed=2A366D601264C712

Failure is:

Failures [shard [[_6tR8K7IRTWe7lCfHvhbPQ][test][3]], reason [RemoteTransportException[[node_s0][local[1]][indices:data/read/search[phase/query]]]; nested: QueryPhaseExecutionException[[test][3]: query[function score (test:value,function=script[doc['num1'].value], params [null])],from[0],size[10]: Query Failed [Failed to execute main query]]; nested: AbstractMethodError[org.apache.lucene.search.Weight.scorer(Lorg/apache/lucene/index/LeafReaderContext;Lorg/apache/lucene/util/Bits;)Lorg/apache/lucene/search/Scorer;]; ], shard [[mCTQY8lPRxCjZx9pfl6VAw][test][5]], reason [QueryPhaseExecutionException[[test][5]: query[function score (test:value,function=script[doc['num1'].value], params [null])],from[0],size[10]: Query Failed [Failed to execute main query]]; nested: AbstractMethodError[org.apache.lucene.search.Weight.scorer(Lorg/apache/lucene/index/LeafReaderContext;Lorg/apache/lucene/util/Bits;)Lorg/apache/lucene/search/Scorer;]; ]]

They run fine with elasticsearch 1.x branch (1.5.0-SNAPSHOT).

Missing methods for array params

If I pass in an array like:

script_file: 'myScript',
lang: 'javascript',
params: {
  myParam: [3, 4, 5]
}

Then trying any of these from within myScript.js will fail with a has no method error:

myParam.slice()
myParam.reduce()
myParam.push()

reason: 'EcmaError[TypeError: Cannot find function slice in object [3, 4, 5]. (Script23.js#15)]' },

Add Javascript examples

what about some examples of javascript scripts what can be executed?
is somewhere some documentation for this?
what API is exposed to javascript?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.