ElasticSearch: Unassigned Shards, how to fix?

By default, Elasticsearch will re-assign shards to nodes dynamically. However, if you’ve disabled shard allocation (perhaps you did a rolling restart and forgot to re-enable it), you can re-enable shard allocation. # v0.90.x and earlier curl -XPUT ‘localhost:9200/_settings’ -d ‘{ “index.routing.allocation.disable_allocation”: false }’ # v1.0+ curl -XPUT ‘localhost:9200/_cluster/settings’ -d ‘{ “transient” : { “cluster.routing.allocation.enable” : … Read more

Elasticsearch , Max length of mapping type long

That’s due to a rounding issue for IEEE-754 double-precision floating point values. Whole values up until 53 bits can be represented safely, however, 10160815114820887 is 54 bits long (100100000110010011010100011111100011000001110100010111) The real number you have indexed was indeed 10160815114820887, but due to the above-mentioned rounding issues, it was indexed and shows as 10160815114820888 You can try … Read more

Insert multiple documents in Elasticsearch – bulk doc formatter

You could utilize the bulk method of the official python package: import json from noaa_sdk import noaa from elasticsearch import Elasticsearch from elasticsearch.helpers import bulk noaa_client = noaa.NOAA() alerts = noaa_client.alerts()[‘features’] es = Elasticsearch() def save_alerts(): with open(‘nhc_alerts.json’, ‘w’) as f: f.write(json.dumps(alerts)) def bulk_sync(): actions = [ { “_index”: “my_noaa_index”, “_source”: alert } for alert … Read more

How to iterate through a nested array in elasticsearch with filter script?

Nested documents are powerful because you retain certain attribute connections but there’s the downside of not being able to iterate over them as discussed here. With that being said you could flatten the users attributes using the copy_to feature like so: PUT my-index-000001 { “mappings”: { “properties”: { “user__first_flattened”: { “type”: “keyword” }, “user”: { … Read more

How to start elasticsearch 5.1 embedded in my java application?

Embedding elasticsearch is no longer officially supported, and it’s a bit more complicated than in 2.x, but it works. You need to add some dependencies: <dependency> <groupId>org.elasticsearch</groupId> <artifactId>elasticsearch</artifactId> <version>5.1.1</version> <scope>test</scope> </dependency> <dependency><!– required by elasticsearch –> <groupId>org.elasticsearch.plugin</groupId> <artifactId>transport-netty4-client</artifactId> <version>5.1.1</version> <scope>test</scope> </dependency> <dependency><!– required by elasticsearch –> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-api</artifactId> <version>2.7</version> </dependency> And then launch a node … Read more