MCPcopy Index your code
hub / github.com/elastic/elasticsearch-hadoop

github.com/elastic/elasticsearch-hadoop @v9.4.3

Chat with this repo
repository ↗ · DeepWiki ↗ · release v9.4.3 ↗ · + Follow
4,273 symbols 17,117 edges 500 files 443 documented · 10%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Elasticsearch Hadoop Build Status

Elasticsearch real-time search and analytics natively integrated with Hadoop. Supports Map/Reduce, Apache Hive, and Apache Spark.

See project page and documentation for detailed information.

Requirements

Elasticsearch cluster accessible through REST. That's it! Significant effort has been invested to create a small, dependency-free, self-contained jar that can be downloaded andput to use without any dependencies. Simply make it available to your job classpath and you're set. For a certain library, see the dedicated chapter.

While an effort has been made to keep ES-Hadoop backwards compatible with older versions of Elasticsearch, it is best to use the version of ES-Hadoop that is the same as the Elasticsearch version. See the product compatibility support matrix for more information.

Installation

Stable Release (9.0.0 used in the examples below)

Support for Hadoop is available through any Maven-compatible tool:

<dependency>
  <groupId>org.elasticsearch</groupId>
  <artifactId>elasticsearch-hadoop</artifactId>
  <version>9.4.2</version>
</dependency>

or as a stand-alone ZIP.

Spark support depends on the versions of Spark and Scala your cluster uses. For Scala 2.12 and Spark 3.0, 3.1, 3.2, 3.3, or 3.4, use:

<dependency>
  <groupId>org.elasticsearch</groupId>
  <artifactId>elasticsearch-spark-30_2.12</artifactId>
  <version>9.0.0</version>
</dependency>

For Scala 2.13 and Spark 3.2, 3.3, or 3.4, use:

<dependency>
  <groupId>org.elasticsearch</groupId>
  <artifactId>elasticsearch-spark-30_2.13</artifactId>
  <version>9.0.0</version>
</dependency>

Supported Hadoop Versions

ES-Hadoop is developed for and tested against Hadoop 2.x and 3.x on YARN. More information in this section.

Supported Spark Versions

Spark 3.0 through 3.4 are supported. Only Scala 2.12 is supported for Spark 3.0 and 3.1. Both Scala 2.12 and 2.13 are supported for Spark 3.2 and higher.

Feedback / Q&A

We're interested in your feedback! You can find us on the Elastic forum.

Online Documentation

The latest reference documentation is available online on the project home page. Below the README contains basic usage instructions at a glance.

Usage

Configuration Properties

All configuration properties start with es prefix. Note that the es.internal namespace is reserved for the library internal use and should not be used by the user at any point. The properties are read mainly from the Hadoop configuration but the user can specify (some of) them directly depending on the library used.

Required

es.resource=<ES resource location, relative to the host/port specified above>

Essential

es.query=<uri or query dsl query>              # defaults to {"query":{"match_all":{}}}
es.nodes=<ES host address>                     # defaults to localhost
es.port=<ES REST port>                         # defaults to 9200

The full list is available here

Map/Reduce

For basic, low-level or performance-sensitive environments, ES-Hadoop provides dedicated InputFormat and OutputFormat that read and write data to Elasticsearch. To use them, add the es-hadoop jar to your job classpath (either by bundling the library along - it's ~300kB and there are no-dependencies), using the DistributedCache or by provisioning the cluster manually. See the documentation for more information.

Note that es-hadoop supports the Hadoop API through its EsInputFormat and EsOutputFormat classes.

Reading

Configuration conf = new Configuration();
conf.set("es.resource", "radio/artists");
conf.set("es.query", "?q=me*");             // replace this with the relevant query
Job job = new Job(conf)
job.setInputFormatClass(EsInputFormat.class);
...
job.waitForCompletion(true);

Writing

Configuration conf = new Configuration();
conf.set("es.resource", "radio/artists"); // index or indices used for storing data
Job job = new Job(conf)
job.setOutputFormatClass(EsOutputFormat.class);
...
job.waitForCompletion(true);

Apache Hive

ES-Hadoop provides a Hive storage handler for Elasticsearch, meaning one can define an external table on top of ES.

Add es-hadoop-.jar to hive.aux.jars.path or register it manually in your Hive script (recommended):

ADD JAR /path_to_jar/es-hadoop-<version>.jar;

Reading

To read data from ES, define a table backed by the desired index:

CREATE EXTERNAL TABLE artists (
    id      BIGINT,
    name    STRING,
    links   STRUCT<url:STRING, picture:STRING>)
STORED BY 'org.elasticsearch.hadoop.hive.EsStorageHandler'
TBLPROPERTIES('es.resource' = 'radio/artists', 'es.query' = '?q=me*');

The fields defined in the table are mapped to the JSON when communicating with Elasticsearch. Notice the use of TBLPROPERTIES to define the location, that is the query used for reading from this table.

Once defined, the table can be used just like any other:

SELECT * FROM artists;

Writing

To write data, a similar definition is used but with a different es.resource:

CREATE EXTERNAL TABLE artists (
    id      BIGINT,
    name    STRING,
    links   STRUCT<url:STRING, picture:STRING>)
STORED BY 'org.elasticsearch.hadoop.hive.EsStorageHandler'
TBLPROPERTIES('es.resource' = 'radio/artists');

Any data passed to the table is then passed down to Elasticsearch; for example considering a table s, mapped to a TSV/CSV file, one can index it to Elasticsearch like this:

INSERT OVERWRITE TABLE artists
    SELECT NULL, s.name, named_struct('url', s.url, 'picture', s.picture) FROM source s;

As one can note, currently the reading and writing are treated separately but we're working on unifying the two and automatically translating HiveQL to Elasticsearch queries.

Apache Spark

ES-Hadoop provides native (Java and Scala) integration with Spark: for reading a dedicated RDD and for writing, methods that work on any RDD. Spark SQL is also supported

Reading

To read data from ES, create a dedicated RDD and specify the query as an argument:

import org.elasticsearch.spark._

..
val conf = ...
val sc = new SparkContext(conf)
sc.esRDD("radio/artists", "?q=me*")

Spark SQL

import org.elasticsearch.spark.sql._

// DataFrame schema automatically inferred
val df = sqlContext.read.format("es").load("buckethead/albums")

// operations get pushed down and translated at runtime to Elasticsearch QueryDSL
val playlist = df.filter(df("category").equalTo("pikes").and(df("year").geq(2016)))

Writing

Import the org.elasticsearch.spark._ package to gain savetoEs methods on your RDDs:

import org.elasticsearch.spark._

val conf = ...
val sc = new SparkContext(conf)

val numbers = Map("one" -> 1, "two" -> 2, "three" -> 3)
val airports = Map("OTP" -> "Otopeni", "SFO" -> "San Fran")

sc.makeRDD(Seq(numbers, airports)).saveToEs("spark/docs")

Spark SQL

import org.elasticsearch.spark.sql._

val df = sqlContext.read.json("examples/people.json")
df.saveToEs("spark/people")

Java

In a Java environment, use the org.elasticsearch.spark.rdd.java.api package, in particular the JavaEsSpark class.

Reading

To read data from ES, create a dedicated RDD and specify the query as an argument.

import org.apache.spark.api.java.JavaSparkContext;
import org.elasticsearch.spark.rdd.api.java.JavaEsSpark;

SparkConf conf = ...
JavaSparkContext jsc = new JavaSparkContext(conf);

JavaPairRDD<String, Map<String, Object>> esRDD = JavaEsSpark.esRDD(jsc, "radio/artists");

Spark SQL

SQLContext sql = new SQLContext(sc);
DataFrame df = sql.read().format("es").load("buckethead/albums");
DataFrame playlist = df.filter(df.col("category").equalTo("pikes").and(df.col("year").geq(2016)))

Writing

Use JavaEsSpark to index any RDD to Elasticsearch:

import org.elasticsearch.spark.rdd.api.java.JavaEsSpark;

SparkConf conf = ...
JavaSparkContext jsc = new JavaSparkContext(conf);

Map<String, ?> numbers = ImmutableMap.of("one", 1, "two", 2);
Map<String, ?> airports = ImmutableMap.of("OTP", "Otopeni", "SFO", "San Fran");

JavaRDD<Map<String, ?>> javaRDD = jsc.parallelize(ImmutableList.of(numbers, airports));
JavaEsSpark.saveToEs(javaRDD, "spark/docs");

Spark SQL

import org.elasticsearch.spark.sql.api.java.JavaEsSparkSQL;

DataFrame df = sqlContext.read.json("examples/people.json")
JavaEsSparkSQL.saveToEs(df, "spark/docs")

Building the source

Elasticsearch Hadoop uses Gradle for its build system and it is not required to have it installed on your machine. By default (gradlew), it automatically builds the package and runs the unit tests. For integration testing, use the integrationTests task. See gradlew tasks for more information.

To create a distributable zip, run gradlew distZip from the command line; once completed you will find the jar in build/libs.

To build the project, JVM 8 (Oracle one is recommended) or higher is required.

License

This project is released under version 2.0 of the Apache License

Licensed to Elasticsearch under one or more contributor
license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright
ownership. Elasticsearch licenses this file to you 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.

Extension points exported contracts — how you extend this code

SettingsAware (Interface)
Whether a ValueReader/Writer need extra configuration properties. [19 implementers]
mr/src/main/java/org/elasticsearch/hadoop/serialization/SettingsAware.java
Fixture (Interface)
Any object that can produce an accompanying stop task, meant to tear down a previously instantiated service.
buildSrc/src/main/java/org/elasticsearch/hadoop/gradle/buildtools/Fixture.java
BulkCommand (Interface)
Bulk command to execute. [24 implementers]
mr/src/main/java/org/elasticsearch/hadoop/serialization/bulk/BulkCommand.java
ValueWriter (Interface)
Translates a value to its JSON-like structure. Implementations should handle filtering of field names. [23 implementers]
mr/src/main/java/org/elasticsearch/hadoop/serialization/builder/ValueWriter.java
FieldExtractor (Interface)
Basic extractor (for serialization purposes) of a field. Typically used with SettingsAware for configuration/inj [20 implementers]
mr/src/main/java/org/elasticsearch/hadoop/serialization/field/FieldExtractor.java
ReusableInputStream (Interface)
Marker interface indicating whether the underlying inputstream can be reused/replayed. [12 implementers]
mr/src/main/java/org/elasticsearch/hadoop/rest/ReusableInputStream.java

Core symbols most depended-on inside this repo

get
called by 528
mr/src/main/java/org/elasticsearch/hadoop/serialization/bulk/MetadataExtractor.java
toString
called by 331
mr/src/main/java/org/elasticsearch/hadoop/serialization/field/FieldExplainer.java
add
called by 316
mr/src/main/java/org/elasticsearch/hadoop/util/BytesRef.java
set
called by 258
mr/src/main/java/org/elasticsearch/hadoop/mr/HadoopCfgUtils.java
println
called by 251
mr/src/main/java/org/elasticsearch/hadoop/cli/Prompt.java
format
called by 228
mr/src/main/java/org/elasticsearch/hadoop/serialization/field/IndexFormatter.java
execute
called by 216
hive/src/itest/java/org/elasticsearch/hadoop/integration/hive/HiveInstance.java
getProperty
called by 204
mr/src/main/java/org/elasticsearch/hadoop/cfg/Settings.java

Shape

Method 3,628
Class 565
Interface 55
Enum 25

Languages

Java100%

Modules by API surface

mr/src/main/java/org/elasticsearch/hadoop/cfg/Settings.java151 symbols
mr/src/main/java/org/elasticsearch/hadoop/rest/RestClient.java49 symbols
buildSrc/src/main/java/org/elasticsearch/hadoop/gradle/scala/SparkVariantPlugin.java46 symbols
mr/src/test/java/org/elasticsearch/hadoop/rest/bulk/BulkProcessorTest.java45 symbols
mr/src/test/java/org/elasticsearch/hadoop/serialization/CommandTest.java43 symbols
mr/src/test/java/org/elasticsearch/hadoop/serialization/ScrollReaderTest.java42 symbols
mr/src/main/java/org/elasticsearch/hadoop/serialization/builder/JdkValueReader.java42 symbols
mr/src/main/java/org/elasticsearch/hadoop/mr/EsInputFormat.java41 symbols
mr/src/itest/java/org/elasticsearch/hadoop/integration/mr/AbstractMROldApiSaveTest.java40 symbols
mr/src/main/java/org/elasticsearch/hadoop/util/unit/TimeValue.java37 symbols
spark/sql-30/src/itest/java/org/elasticsearch/spark/integration/AbstractJavaEsSparkStreamingTest.java36 symbols
hive/src/itest/java/org/elasticsearch/hadoop/integration/hive/AbstractHiveSaveTest.java36 symbols

For agents

$ claude mcp add elasticsearch-hadoop \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact