- Elasticsearch Guide: other versions:
- Getting Started
- Setup
- Breaking changes
- API Conventions
- Document APIs
- Search APIs
- Search
- URI Search
- Request Body Search
- Search Template
- Search Shards API
- Aggregations
- Min Aggregation
- Max Aggregation
- Sum Aggregation
- Avg Aggregation
- Stats Aggregation
- Extended Stats Aggregation
- Value Count Aggregation
- Percentiles Aggregation
- Percentile Ranks Aggregation
- Cardinality Aggregation
- Geo Bounds Aggregation
- Top hits Aggregation
- Scripted Metric Aggregation
- Global Aggregation
- Filter Aggregation
- Filters Aggregation
- Missing Aggregation
- Nested Aggregation
- Reverse nested Aggregation
- Children Aggregation
- Terms Aggregation
- Significant Terms Aggregation
- Range Aggregation
- Date Range Aggregation
- IPv4 Range Aggregation
- Histogram Aggregation
- Date Histogram Aggregation
- Geo Distance Aggregation
- GeoHash grid Aggregation
- Facets
- Suggesters
- Multi Search API
- Count API
- Search Exists API
- Validate API
- Explain API
- Percolator
- More Like This API
- Indices APIs
- Create Index
- Delete Index
- Get Index
- Indices Exists
- Open / Close Index API
- Put Mapping
- Get Mapping
- Get Field Mapping
- Types Exists
- Delete Mapping
- Index Aliases
- Update Indices Settings
- Get Settings
- Analyze
- Index Templates
- Warmers
- Status
- Indices Stats
- Indices Segments
- Indices Recovery
- Clear Cache
- Flush
- Refresh
- Optimize
- Upgrade
- Shadow replica indices
- cat APIs
- Cluster APIs
- Query DSL
- Queries
- Match Query
- Multi Match Query
- Bool Query
- Boosting Query
- Common Terms Query
- Constant Score Query
- Dis Max Query
- Filtered Query
- Fuzzy Like This Query
- Fuzzy Like This Field Query
- Function Score Query
- Fuzzy Query
- GeoShape Query
- Has Child Query
- Has Parent Query
- Ids Query
- Indices Query
- Match All Query
- More Like This Query
- Nested Query
- Prefix Query
- Query String Query
- Simple Query String Query
- Range Query
- Regexp Query
- Span First Query
- Span Multi Term Query
- Span Near Query
- Span Not Query
- Span Or Query
- Span Term Query
- Term Query
- Terms Query
- Top Children Query
- Wildcard Query
- Minimum Should Match
- Multi Term Query Rewrite
- Template Query
- Filters
- And Filter
- Bool Filter
- Exists Filter
- Geo Bounding Box Filter
- Geo Distance Filter
- Geo Distance Range Filter
- Geo Polygon Filter
- GeoShape Filter
- Geohash Cell Filter
- Has Child Filter
- Has Parent Filter
- Ids Filter
- Indices Filter
- Limit Filter
- Match All Filter
- Missing Filter
- Nested Filter
- Not Filter
- Or Filter
- Prefix Filter
- Query Filter
- Range Filter
- Regexp Filter
- Script Filter
- Term Filter
- Terms Filter
- Type Filter
- Queries
- Mapping
- Analysis
- Analyzers
- Tokenizers
- Token Filters
- Standard Token Filter
- ASCII Folding Token Filter
- Length Token Filter
- Lowercase Token Filter
- Uppercase Token Filter
- NGram Token Filter
- Edge NGram Token Filter
- Porter Stem Token Filter
- Shingle Token Filter
- Stop Token Filter
- Word Delimiter Token Filter
- Stemmer Token Filter
- Stemmer Override Token Filter
- Keyword Marker Token Filter
- Keyword Repeat Token Filter
- KStem Token Filter
- Snowball Token Filter
- Phonetic Token Filter
- Synonym Token Filter
- Compound Word Token Filter
- Reverse Token Filter
- Elision Token Filter
- Truncate Token Filter
- Unique Token Filter
- Pattern Capture Token Filter
- Pattern Replace Token Filter
- Trim Token Filter
- Limit Token Count Token Filter
- Hunspell Token Filter
- Common Grams Token Filter
- Normalization Token Filter
- CJK Width Token Filter
- CJK Bigram Token Filter
- Delimited Payload Token Filter
- Keep Words Token Filter
- Keep Types Token Filter
- Classic Token Filter
- Apostrophe Token Filter
- Character Filters
- ICU Analysis Plugin
- Modules
- Index Modules
- Testing
- Glossary of terms
WARNING: Version 1.5 of Elasticsearch has passed its EOL date.
This documentation is no longer being maintained and may be removed. If you are running this version, we strongly advise you to upgrade. For the latest information, see the current release documentation.
integration tests
editintegration tests
editThese kind of tests require firing up a whole cluster of nodes, before the tests can actually be run. Compared to unit tests they are obviously way more time consuming, but the test infrastructure tries to minimize the time cost by only restarting the whole cluster, if this is configured explicitly.
The class your tests have to inherit from is ElasticsearchIntegrationTest
. As soon as you inherit, there is no need for you to start any elasticsearch nodes manually in your test anymore, though you might need to ensure that at least a certain number of nodes is up.
number of shards
editThe number of shards used for indices created during integration tests is randomized between 1
and 10
unless overwritten upon index creation via index settings.
Rule of thumb is not to specify the number of shards unless needed, so that each test will use a different one all the time.
generic helper methods
editThere are a couple of helper methods in ElasticsearchIntegrationTest
, which will make your tests shorter and more concise.
|
Refreshes all indices in a cluster |
|
Ensures a green health cluster state, waiting for relocations. Waits the default timeout of 30 seconds before failing. |
|
Ensures a yellow health cluster state, also waits for 30 seconds before failing. |
|
Creates an index with the specified name |
|
Flushes all indices in a cluster |
|
Combines |
|
Waits for all relocations and optimized all indices in the cluster to one segment. |
|
Checks if given index exists |
|
Returns an |
|
Returns the cluster service java class |
|
Returns the test cluster class, which is explained in the next paragraphs |
test cluster methods
editThe TestCluster
class is the heart of the cluster functionality in a randomized test and allows you to configure a specific setting or replay certain types of outages to check, how your custom code reacts.
|
Ensure at least the specified number of nodes is running in the cluster |
|
Ensure at most the specified number of nodes is running in the cluster |
|
Get a guice instantiated instance of a class from a random node |
|
Get a guice instantiated instance of a class from a specified node |
|
Stop a random node in your cluster to mimic an outage |
|
Stop the current master node to force a new election |
|
Stop a random non master node to mimic an outage |
|
Create a new elasticsearch node |
|
Create and start a new elasticsearch node |
Accessing clients
editIn order to execute any actions, you have to use a client. You can use the ElasticsearchIntegrationTest.client()
method to get back a random client. This client can be a TransportClient
or a NodeClient
- and usually you do not need to care as long as the action gets executed. There are several more methods for client selection inside of the TestCluster
class, which can be accessed using the ElasticsearchIntegrationTest.cluster()
method.
|
An iterator over all available clients |
|
Returns a client which is connected to the master node |
|
Returns a client which is not connected to the master node |
|
Returns a client, which is running on a client node |
|
Returns a client to a given node |
|
Returns a smart client |
Scoping
editBy default the tests are run with unique cluster per test suite. Of course all indices and templates are deleted between each test. However, sometimes you need to start a new cluster for each test - for example, if you load a certain plugin, but you do not want to load it for every test.
You can use the @ClusterScope
annotation at class level to configure this behaviour
@ClusterScope(scope=TEST, numNodes=1) public class CustomSuggesterSearchTests extends ElasticsearchIntegrationTest { // ... tests go here }
The above sample configures the test to use a new cluster for each test method. The default scope is SUITE
(one cluster for all test methods in the test). The numNodes
settings allows you to only start a certain number of nodes, which can speed up test execution, as starting a new node is a costly and time consuming operation and might not be needed for this test.
Changing node configuration
editAs elasticsearch is using JUnit 4, using the @Before
and @After
annotations is not a problem. However you should keep in mind, that this does not have any effect in your cluster setup, as the cluster is already up and running when those methods are run. So in case you want to configure settings - like loading a plugin on node startup - before the node is actually running, you should overwrite the nodeSettings()
method from the ElasticsearchIntegrationTest
class and change the cluster scope to SUITE
.
@Override protected Settings nodeSettings(int nodeOrdinal) { return ImmutableSettings.settingsBuilder() .put("plugin.types", CustomSuggesterPlugin.class.getName()) .put(super.nodeSettings(nodeOrdinal)).build(); }
On this page