Skip to content

Instantly share code, notes, and snippets.

@hkorte
hkorte / PutStoredScriptExample.java
Last active September 14, 2018 13:22
This example shows a strange behavior of the Elasticsearch TransportClient in version 5.6.11
package test;
import org.apache.http.HttpEntity;
import org.apache.http.HttpHost;
import org.apache.http.entity.ContentType;
import org.apache.http.nio.entity.NStringEntity;
import org.apache.http.util.EntityUtils;
import org.elasticsearch.client.Response;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.transport.TransportClient;
@hkorte
hkorte / TopHitsAggWithoutFieldsTest.java
Last active August 29, 2015 14:18
Elasticsearch: Java API allows to create invalid queries by adding a top_hits aggregation without fields
package sandbox;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.aggregations.AggregationBuilders;
import org.elasticsearch.test.ElasticsearchIntegrationTest;
import org.junit.Before;
import org.junit.Test;
/**
@hkorte
hkorte / Elasticsearch: exist filter also matching on nested fields
Created February 10, 2015 15:35
An Elasticsearch gist for the thread "exist filter also matching on nested fields": https://groups.google.com/forum/#!topic/elasticsearch/8R9XgVkCZIU
# Remove old data
curl -XDELETE "http://localhost:9200/nestedfiltertest?pretty"
# Create index with nested type mapping
curl -XPUT "http://localhost:9200/nestedfiltertest/?pretty" -d '
{
"mappings": {
"doc": {
"properties": {
"nested": {
@hkorte
hkorte / elasticsearchInMemoryWithGroovy.md
Last active August 29, 2015 14:04
Elasticsearch 1.3.1 in-memory with groovy support

Recently I was upgrading from Elasticsearch 1.1.1 to 1.3.1 and I wanted to change a dynamic script from MVEL to Groovy as MVEL is not sandboxed and thus deprecated. While all my manual tests on a standalone ES 1.3.1 worked perfectly, my automated tests running an in-memory ES node kept on failing with:

ElasticsearchIllegalArgumentException[script_lang not supported [groovy]];

I then changed the log level and saw this:

DEBUG org.elasticsearch.script - [Spymaster] failed to load groovy
@hkorte
hkorte / significant-terms-field-resolution.sh
Last active August 29, 2015 13:58
This gist describes different problems in Elasticsearch 1.1.0 and in the current master (2014-04-04) with the field resolution in the significant terms aggregations when prepending the document type to the field name.
curl -XDELETE 'http://localhost:9200/testindex?pretty=true'
curl -XPUT 'http://localhost:9200/testindex/testdoc/doc01?pretty=true' -d '{ "text": "Many countries currently have an assembly named a senate, composed of senators who may be elected, appointed, have inherited the title, or gained membership by other methods, depending on the country." }'
curl -XPUT 'http://localhost:9200/testindex/testdoc/doc02?pretty=true' -d '{ "text": "In Germany, the last Senate of a State parliament, the Senate of Bavaria, was abolished in 1999." }'
curl -XPUT 'http://localhost:9200/testindex/testdoc/doc03?pretty=true' -d '{ "text": "The economy is fueled by an abundance of natural resources and a high worker productivity." }'
curl -XPUT 'http://localhost:9200/testindex/testdoc/doc04?pretty=true' -d '{ "text": "The atoms of metallic substances are closely positioned to neighboring atoms in one of two common arrangements." }'
curl -XPUT 'http://localhost:9200/testindex/testdoc/doc05?pretty=true' -d '{ "text": "Atoms of metals r
@hkorte
hkorte / elasticsearch-missing-geo-value.sh
Created April 2, 2014 15:13
A change in geo_point parsing in Elasticsearch 1.1.0 leads to a different treatment of input documents without a valid geo_point. My application produced JSON documents containing "location:{}", which is not accepted as a missing value anymore. So in case you also see Exceptions like "MapperParsingException[failed to parse]; nested: Elasticsearc…
curl -XDELETE 'http://localhost:9200/testindex?pretty=true'
curl -XPOST 'http://localhost:9200/testindex?pretty=true' -d '
{
"mappings": {
"testdoc": {
"properties": {
"name": {
"type": "string"
},
"location": {
@hkorte
hkorte / boostsorttest-verbose.sh
Created September 17, 2013 09:51
Defining a field as boost removes this field's properties. Thus, it is impossible to sort on the boost field. The last search with sorting the bothdocs shows the problem with "sort" : [ "-Infinity" ].
curl -XDELETE 'http://localhost:9200/boosttest'
curl -XPOST 'http://localhost:9200/boosttest' -d '{
"mappings" : {
"sortdoc": {
"properties" : {
"my_boost":{
"type":"float"
}
}
},
@hkorte
hkorte / boostsorttest.sh
Created September 17, 2013 09:46
Defining a field as boost removes this field's properties. Thus, it is impossible to sort on the boost field.
curl -XDELETE 'http://localhost:9200/boosttest'
curl -XPOST 'http://localhost:9200/boosttest' -d '{
"mappings" : {
"withoutboost": {
"properties" : {
"my_boost":{
"type":"float"
}
}
},