├── .gitignore ├── .travis.yml ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── jest-common ├── pom.xml └── src │ ├── main │ └── java │ │ └── io │ │ └── searchbox │ │ ├── action │ │ ├── AbstractAction.java │ │ ├── AbstractDocumentTargetedAction.java │ │ ├── AbstractMultiINodeActionBuilder.java │ │ ├── AbstractMultiIndexActionBuilder.java │ │ ├── AbstractMultiTypeActionBuilder.java │ │ ├── Action.java │ │ ├── BulkableAction.java │ │ ├── DocumentTargetedAction.java │ │ ├── GenericResultAbstractAction.java │ │ ├── GenericResultAbstractDocumentTargetedAction.java │ │ └── SingleResultAbstractDocumentTargetedAction.java │ │ ├── annotations │ │ ├── JestId.java │ │ └── JestVersion.java │ │ ├── client │ │ ├── AbstractJestClient.java │ │ ├── JestClient.java │ │ ├── JestResult.java │ │ ├── JestResultHandler.java │ │ └── config │ │ │ ├── ClientConfig.java │ │ │ ├── ElasticsearchVersion.java │ │ │ ├── discovery │ │ │ └── NodeChecker.java │ │ │ ├── exception │ │ │ ├── CouldNotConnectException.java │ │ │ └── NoServerConfiguredException.java │ │ │ └── idle │ │ │ ├── IdleConnectionReaper.java │ │ │ └── ReapableConnectionManager.java │ │ ├── cloning │ │ └── CloneUtils.java │ │ ├── cluster │ │ ├── GetSettings.java │ │ ├── Health.java │ │ ├── NodesHotThreads.java │ │ ├── NodesInfo.java │ │ ├── NodesShutdown.java │ │ ├── NodesStats.java │ │ ├── PendingClusterTasks.java │ │ ├── Reroute.java │ │ ├── State.java │ │ ├── Stats.java │ │ ├── TasksInformation.java │ │ ├── UpdateSettings.java │ │ └── reroute │ │ │ ├── RerouteAllocateReplica.java │ │ │ ├── RerouteCancel.java │ │ │ ├── RerouteCommand.java │ │ │ └── RerouteMove.java │ │ ├── core │ │ ├── Bulk.java │ │ ├── BulkResult.java │ │ ├── Cat.java │ │ ├── CatResult.java │ │ ├── ClearScroll.java │ │ ├── Count.java │ │ ├── CountResult.java │ │ ├── Delete.java │ │ ├── DeleteByQuery.java │ │ ├── Doc.java │ │ ├── DocumentResult.java │ │ ├── Explain.java │ │ ├── Get.java │ │ ├── Index.java │ │ ├── MultiGet.java │ │ ├── MultiSearch.java │ │ ├── MultiSearchResult.java │ │ ├── Ping.java │ │ ├── Search.java │ │ ├── SearchResult.java │ │ ├── SearchScroll.java │ │ ├── SearchShards.java │ │ ├── Update.java │ │ ├── UpdateByQuery.java │ │ ├── UpdateByQueryResult.java │ │ ├── Validate.java │ │ └── search │ │ │ ├── aggregation │ │ │ ├── Aggregation.java │ │ │ ├── AggregationField.java │ │ │ ├── AvgAggregation.java │ │ │ ├── Bucket.java │ │ │ ├── BucketAggregation.java │ │ │ ├── CardinalityAggregation.java │ │ │ ├── ChildrenAggregation.java │ │ │ ├── CompositeAggregation.java │ │ │ ├── DateHistogramAggregation.java │ │ │ ├── DateRangeAggregation.java │ │ │ ├── ExtendedStatsAggregation.java │ │ │ ├── FilterAggregation.java │ │ │ ├── FiltersAggregation.java │ │ │ ├── GeoBoundsAggregation.java │ │ │ ├── GeoDistanceAggregation.java │ │ │ ├── GeoHashGridAggregation.java │ │ │ ├── HistogramAggregation.java │ │ │ ├── Ipv4RangeAggregation.java │ │ │ ├── MaxAggregation.java │ │ │ ├── MetricAggregation.java │ │ │ ├── MinAggregation.java │ │ │ ├── MissingAggregation.java │ │ │ ├── PercentileRanksAggregation.java │ │ │ ├── PercentilesAggregation.java │ │ │ ├── Range.java │ │ │ ├── RangeAggregation.java │ │ │ ├── RootAggregation.java │ │ │ ├── ScriptedMetricAggregation.java │ │ │ ├── SignificantTermsAggregation.java │ │ │ ├── SingleValueAggregation.java │ │ │ ├── StatsAggregation.java │ │ │ ├── SumAggregation.java │ │ │ ├── TermsAggregation.java │ │ │ ├── TopHitsAggregation.java │ │ │ └── ValueCountAggregation.java │ │ │ └── sort │ │ │ └── Sort.java │ │ ├── fields │ │ └── FieldCapabilities.java │ │ ├── indices │ │ ├── Analyze.java │ │ ├── ClearCache.java │ │ ├── CloseIndex.java │ │ ├── CreateIndex.java │ │ ├── DeleteIndex.java │ │ ├── DocumentExists.java │ │ ├── DocumentExistsResult.java │ │ ├── Flush.java │ │ ├── ForceMerge.java │ │ ├── IndicesExists.java │ │ ├── OpenIndex.java │ │ ├── Optimize.java │ │ ├── Refresh.java │ │ ├── Rollover.java │ │ ├── Segments.java │ │ ├── Snapshot.java │ │ ├── Stats.java │ │ ├── Templates.java │ │ ├── aliases │ │ │ ├── AbstractAliasMappingBuilder.java │ │ │ ├── AddAliasMapping.java │ │ │ ├── AliasExists.java │ │ │ ├── AliasMapping.java │ │ │ ├── GetAliases.java │ │ │ ├── ModifyAliases.java │ │ │ └── RemoveAliasMapping.java │ │ ├── mapping │ │ │ ├── DeleteMapping.java │ │ │ ├── GetMapping.java │ │ │ └── PutMapping.java │ │ ├── reindex │ │ │ └── Reindex.java │ │ ├── script │ │ │ ├── AbstractStoredScript.java │ │ │ ├── CreateStoredScript.java │ │ │ ├── DeleteStoredScript.java │ │ │ ├── GetStoredScript.java │ │ │ └── ScriptLanguage.java │ │ ├── settings │ │ │ ├── GetSettings.java │ │ │ ├── IndicesSettingsAbstractAction.java │ │ │ └── UpdateSettings.java │ │ ├── template │ │ │ ├── DeleteTemplate.java │ │ │ ├── GetTemplate.java │ │ │ ├── PutTemplate.java │ │ │ └── TemplateAction.java │ │ └── type │ │ │ └── TypeExist.java │ │ ├── params │ │ ├── Parameters.java │ │ └── SearchType.java │ │ ├── snapshot │ │ ├── AbstractSnapshotAction.java │ │ ├── AbstractSnapshotRepositoryAction.java │ │ ├── CreateSnapshot.java │ │ ├── CreateSnapshotRepository.java │ │ ├── DeleteSnapshot.java │ │ ├── DeleteSnapshotRepository.java │ │ ├── GetSnapshot.java │ │ ├── GetSnapshotRepository.java │ │ ├── RestoreSnapshot.java │ │ └── SnapshotStatus.java │ │ └── strings │ │ └── StringUtils.java │ └── test │ ├── java │ └── io │ │ └── searchbox │ │ ├── action │ │ └── AbstractActionTest.java │ │ ├── client │ │ ├── AbstractJestClientTest.java │ │ ├── JestResultTest.java │ │ └── config │ │ │ ├── ClientConfigTest.java │ │ │ └── discovery │ │ │ └── NodeCheckerTest.java │ │ ├── cluster │ │ ├── NodesHotThreadsTest.java │ │ ├── NodesInfoTest.java │ │ ├── NodesShutdownTest.java │ │ ├── NodesStatsTest.java │ │ ├── PendingClusterTasksTest.java │ │ ├── RerouteTest.java │ │ ├── StateTest.java │ │ ├── StatsTest.java │ │ ├── TasksInformationTest.java │ │ └── reroute │ │ │ ├── RerouteAllocateReplicaTest.java │ │ │ ├── RerouteCancelTest.java │ │ │ └── RerouteMoveTest.java │ │ ├── core │ │ ├── BulkResultTest.java │ │ ├── BulkTest.java │ │ ├── CatAliasesBuilderTest.java │ │ ├── CatAllocationBuilderTest.java │ │ ├── CatIndicesBuilderTest.java │ │ ├── CatNodesBuilderTest.java │ │ ├── CatRecoveryBuilderTest.java │ │ ├── CatResultTest.java │ │ ├── CatSegmentsBuilderTest.java │ │ ├── CatShardsBuilderTest.java │ │ ├── CountResultTest.java │ │ ├── CountTest.java │ │ ├── DeleteByQueryTest.java │ │ ├── DeleteTest.java │ │ ├── DocTest.java │ │ ├── DocumentResultTest.java │ │ ├── ExplainTest.java │ │ ├── GetTest.java │ │ ├── IndexTest.java │ │ ├── MultiGetTest.java │ │ ├── MultiSearchTest.java │ │ ├── PingTest.java │ │ ├── SearchResultTest.java │ │ ├── SearchScrollTest.java │ │ ├── SearchTest.java │ │ ├── UpdateByQueryTest.java │ │ ├── UpdateTest.java │ │ ├── ValidateTest.java │ │ └── search │ │ │ ├── aggregation │ │ │ ├── CompositeAggregationTest.java │ │ │ └── TermsAggregationTermTest.java │ │ │ └── sort │ │ │ └── SortTest.java │ │ ├── fields │ │ └── FieldsStatsTest.java │ │ ├── indices │ │ ├── AnalyzeTest.java │ │ ├── ClearCacheTest.java │ │ ├── CloseIndexTest.java │ │ ├── CreateIndexTest.java │ │ ├── DeleteIndexTest.java │ │ ├── FlushTest.java │ │ ├── ForceMergeTest.java │ │ ├── IndicesExistsTest.java │ │ ├── OpenIndexTest.java │ │ ├── OptimizeTest.java │ │ ├── RefreshTest.java │ │ ├── RolloverTest.java │ │ ├── StatsTest.java │ │ ├── aliases │ │ │ ├── AddAliasMappingTest.java │ │ │ ├── AliasExistsTest.java │ │ │ ├── GetAliasesTest.java │ │ │ ├── ModifyAliasesTest.java │ │ │ └── RemoveAliasMappingTest.java │ │ ├── mapping │ │ │ ├── DeleteMappingTest.java │ │ │ ├── GetMappingTest.java │ │ │ └── PutMappingTest.java │ │ ├── reindex │ │ │ └── ReindexTest.java │ │ ├── script │ │ │ ├── CreateStoredScriptTest.java │ │ │ ├── DeleteStoredScriptTest.java │ │ │ └── GetStoredScriptTest.java │ │ ├── settings │ │ │ ├── GetSettingsTest.java │ │ │ └── UpdateSettingsTest.java │ │ ├── template │ │ │ ├── DeleteTemplateTest.java │ │ │ ├── GetTemplateTest.java │ │ │ └── PutTemplateTest.java │ │ └── type │ │ │ └── TypeExistTest.java │ │ ├── search │ │ └── aggregation │ │ │ ├── CardinalityAggregationTest.java │ │ │ ├── ChildAggregationTest.java │ │ │ └── TopHitsAggregationTest.java │ │ └── snapshot │ │ ├── CreateSnapshotRepositoryTest.java │ │ ├── CreateSnapshotTest.java │ │ ├── DeleteSnapshotRepositoryTest.java │ │ ├── DeleteSnapshotTest.java │ │ ├── GetSnapshotRepositoryTest.java │ │ ├── GetSnapshotTest.java │ │ ├── RestoreSnapshotTest.java │ │ └── SnapshotStatusTest.java │ └── resources │ └── io │ └── searchbox │ └── sample_book.json ├── jest-droid ├── README.md ├── pom.xml └── src │ └── main │ └── java │ └── com │ └── searchly │ └── jestdroid │ ├── DroidClientConfig.java │ ├── DroidReapableConnectionManager.java │ ├── JestClientFactory.java │ ├── JestDroidClient.java │ └── http │ ├── HttpDeleteWithEntity.java │ └── HttpGetWithEntity.java ├── jest ├── README.md ├── pom.xml └── src │ ├── main │ └── java │ │ └── io │ │ └── searchbox │ │ └── client │ │ ├── JestClientFactory.java │ │ ├── config │ │ ├── HttpClientConfig.java │ │ └── idle │ │ │ └── HttpReapableConnectionManager.java │ │ └── http │ │ ├── JestHttpClient.java │ │ └── apache │ │ ├── HttpDeleteWithEntity.java │ │ └── HttpGetWithEntity.java │ └── test │ ├── java │ └── io │ │ └── searchbox │ │ ├── client │ │ ├── JestClientFactoryIntegrationTest.java │ │ ├── JestClientFactoryTest.java │ │ ├── config │ │ │ └── HttpClientConfigTest.java │ │ └── http │ │ │ ├── FailingProxy.java │ │ │ ├── FailingProxyTest.java │ │ │ ├── JestHttpClientConfiguredProxyIntegrationTest.java │ │ │ ├── JestHttpClientSystemWideProxyIntegrationTest.java │ │ │ └── JestHttpClientTest.java │ │ ├── cluster │ │ ├── GetSettingsIntegrationTest.java │ │ ├── HealthIntegrationTest.java │ │ ├── NodesHotThreadsIntegrationTest.java │ │ ├── NodesInfoIntegrationTest.java │ │ ├── NodesStatsIntegrationTest.java │ │ ├── PendingClusterTasksIntegrationTest.java │ │ ├── RerouteIntegrationTest.java │ │ ├── StateIntegrationTest.java │ │ ├── StatsIntegrationTest.java │ │ ├── TaskInformationIntegrationTest.java │ │ └── UpdateSettingsIntegrationTest.java │ │ ├── common │ │ └── AbstractIntegrationTest.java │ │ ├── core │ │ ├── BulkIntegrationTest.java │ │ ├── CatIntegrationTest.java │ │ ├── CountIntegrationTest.java │ │ ├── DeleteByQueryIntegrationTest.java │ │ ├── DeleteIntegrationTest.java │ │ ├── ExplainIntegrationTest.java │ │ ├── GetIntegrationTest.java │ │ ├── IndexIntegrationTest.java │ │ ├── MultiGetIntegrationTest.java │ │ ├── MultiSearchIntegrationTest.java │ │ ├── PingIntegrationTest.java │ │ ├── SearchIntegrationTest.java │ │ ├── SearchScrollIntegrationTest.java │ │ ├── SearchShardsIntegrationTest.java │ │ ├── SearchTemplateIntegrationTest.java │ │ ├── TestArticleModel.java │ │ ├── UpdateByQueryIntegrationTest.java │ │ ├── UpdateIntegrationTest.java │ │ ├── ValidateIntegrationTest.java │ │ └── search │ │ │ ├── aggregation │ │ │ ├── AvgAggregationIntegrationTest.java │ │ │ ├── CardinalityAggregationIntegrationTest.java │ │ │ ├── CompositeAggregationIntegrationTest.java │ │ │ ├── DateHistogramAggregationIntegrationTest.java │ │ │ ├── DateRangeAggregationIntegrationTest.java │ │ │ ├── ExtendedStatsAggregationIntegrationTest.java │ │ │ ├── FilterAggregationIntegrationTest.java │ │ │ ├── FiltersAggregationIntegrationTest.java │ │ │ ├── GeoBoundsAggregationIntegrationTest.java │ │ │ ├── GeoDistanceAggregationTest.java │ │ │ ├── GeoHashGridAggregationIntegrationTest.java │ │ │ ├── HistogramAggregationIntegrationTest.java │ │ │ ├── Ipv4RangeAggregationIntegrationTest.java │ │ │ ├── MaxAggregationIntegrationTest.java │ │ │ ├── MinAggregationIntegrationTest.java │ │ │ ├── MissingAggregationIntegrationTest.java │ │ │ ├── PercentileRanksAggregationIntegrationTest.java │ │ │ ├── PercentilesAggregationIntegrationTest.java │ │ │ ├── RangeAggregationIntegrationTest.java │ │ │ ├── ScriptedMetricAggregationIntegrationTest.java │ │ │ ├── SignificantTermsAggregationIntegrationTest.java │ │ │ ├── StatsAggregationIntegrationTest.java │ │ │ ├── SumAggregationIntegrationTest.java │ │ │ ├── TermsAggregationIntegrationTest.java │ │ │ └── ValueCountAggregationIntegrationTest.java │ │ │ └── sort │ │ │ └── SortIntegrationTest.java │ │ ├── fields │ │ └── FieldCapabilitiesIntegrationTest.java │ │ └── indices │ │ ├── AnalyzeIntegrationTest.java │ │ ├── CloseIndexIntegrationTest.java │ │ ├── CreateIndexIntegrationTest.java │ │ ├── DeleteIndexIntegrationTest.java │ │ ├── FlushIntegrationTest.java │ │ ├── ForceMergeIntegrationTest.java │ │ ├── GetMappingIntegrationTest.java │ │ ├── IndicesExistsIntegrationTest.java │ │ ├── OpenIndexIntegrationTest.java │ │ ├── OptimizeIntegrationTest.java │ │ ├── PutMappingIntegrationTest.java │ │ ├── PutTemplateIntegrationTest.java │ │ ├── RefreshIntegrationTest.java │ │ ├── RolloverIntegrationTest.java │ │ ├── StatsIntegrationTest.java │ │ ├── aliases │ │ ├── AliasExistsIntegrationTest.java │ │ ├── GetAliasesIntegrationTest.java │ │ └── ModifyAliasesIntegrationTest.java │ │ ├── reindex │ │ └── ReindexIntegrationTest.java │ │ ├── script │ │ ├── CreateStoredScriptIntegrationTest.java │ │ ├── DeleteStoredScriptIntegrationTest.java │ │ └── GetStoredScriptIntegrationTest.java │ │ ├── settings │ │ ├── GetSettingsIntegrationTest.java │ │ └── UpdateSettingsIntegrationTest.java │ │ └── type │ │ └── TypeExistIntegrationTest.java │ └── resources │ ├── io │ └── searchbox │ │ └── sample_book.json │ └── log4j.properties ├── logo_IntelliJIDEA.svg ├── pom.xml ├── pubring.gpg.enc ├── secring.gpg.enc └── settings.xml /.gitignore: -------------------------------------------------------------------------------- 1 | # Common IDEs 2 | *.iml 3 | .idea/ 4 | build/ 5 | data/ 6 | target/ 7 | .project 8 | .settings 9 | .classpath 10 | .DS_Store 11 | jest/lib 12 | local.* 13 | lib/ 14 | *.versionsBackup 15 | 16 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | dist: trusty 3 | jdk: 4 | - oraclejdk8 5 | sudo: required 6 | env: 7 | global: 8 | - SONATYPE_USERNAME=searchboxadmin 9 | - secure: BBvuAZE4hahFMuOnxpyHtU3CETtXAj0KJ5vbN2WeiJXpnLt0Ct/IbwN2SFMc6iTEmJSzG6Zkk8zTrRajGNM+rPv74rAuYBXDmiBVwJVLX11kLr4Y+S+LNkik1wrUCZjEO6t1kcVq6syYv7rL9Tb+28enIDI+3qvTRNnrNTo86k8= 10 | - secure: jE0ozTLvEvzCaul7opCQAoE8ttNiK+buxeOnsLrVGd1rC1QqfufQoj+pC5RBwgY1w/nN8fQRbi3EgxVZeZwZojQJH7lJIUkH/1iBYO2dqYF3coJQCGF2IQ7KyoRBsLJuO6vZgMR978itNfyBkhKupYzQwA+skrCkQynS6lqhGME= 11 | - secure: kufSuaczK1N07iLL+9NmKAMHKYjtshbqPMbJLqZdAZOPgfKAaEat3dDq/EnryOCvIDZrlQeudn7G3fmIUY76hMdM2pc6vtrA15vSZ4o8RaG9zPPMhmQIQlnq4tdzvpNMlNVB3gFsXXSlBKy6D6jx7hkuffk0akOHp1Q++weP3fo= 12 | 13 | before_install: 14 | - if [ -z "$TRAVIS_SECURE_ENV_VARS" -o "$TRAVIS_SECURE_ENV_VARS" == "false" ]; then echo "Skipping decryption because secure environment variables are not present."; else openssl aes-256-cbc -pass pass:$ENCRYPTION_PASSWORD -in secring.gpg.enc -out local.secring.gpg -d; openssl aes-256-cbc -pass pass:$ENCRYPTION_PASSWORD -in pubring.gpg.enc -out local.pubring.gpg -d; fi; 15 | 16 | after_success: 17 | - mvn clean cobertura:cobertura coveralls:report 18 | - if [ -z "$TRAVIS_SECURE_ENV_VARS" -o "$TRAVIS_SECURE_ENV_VARS" == "false" ]; then echo "Skipping deployment because secure environment variables are not present."; else mvn clean deploy --settings settings.xml -DskipTests=true -B -Psign-artifacts; fi; 19 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Code of Conduct 2 | ## Version 0.4 3 | 4 | As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities. 5 | 6 | If any participant in this project has issues or takes exception with a contribution, they are obligated to provide constructive feedback and never resort to personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct. 7 | 8 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team. 9 | 10 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers. 11 | 12 | We promise to extend courtesy and respect to everyone involved in this project regardless of gender, gender identity, sexual orientation, ability or disability, ethnicity, religion, age, location, native language, or level of experience. -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/action/AbstractDocumentTargetedAction.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.action; 2 | 3 | import io.searchbox.client.JestResult; 4 | import io.searchbox.client.config.ElasticsearchVersion; 5 | import io.searchbox.strings.StringUtils; 6 | 7 | /** 8 | * @author cihat keser 9 | */ 10 | public abstract class AbstractDocumentTargetedAction extends AbstractAction implements DocumentTargetedAction { 11 | 12 | protected String id; 13 | 14 | public AbstractDocumentTargetedAction(Builder builder) { 15 | super(builder); 16 | indexName = builder.index; 17 | typeName = builder.type; 18 | id = builder.id; 19 | } 20 | 21 | @Override 22 | public String getIndex() { 23 | return indexName; 24 | } 25 | 26 | @Override 27 | public String getType() { 28 | return typeName; 29 | } 30 | 31 | @Override 32 | public String getId() { 33 | return id; 34 | } 35 | 36 | @Override 37 | protected String buildURI(ElasticsearchVersion elasticsearchVersion) { 38 | StringBuilder sb = new StringBuilder(super.buildURI(elasticsearchVersion)); 39 | 40 | if (StringUtils.isNotBlank(id)) { 41 | sb.append("/").append(id); 42 | } 43 | return sb.toString(); 44 | } 45 | 46 | @SuppressWarnings("unchecked") 47 | protected abstract static class Builder extends AbstractAction.Builder { 48 | private String index; 49 | private String type; 50 | private String id; 51 | 52 | public K index(String index) { 53 | this.index = index; 54 | return (K) this; 55 | } 56 | 57 | public K type(String type) { 58 | this.type = type; 59 | return (K) this; 60 | } 61 | 62 | public K id(String id) { 63 | this.id = id; 64 | return (K) this; 65 | } 66 | 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/action/AbstractMultiIndexActionBuilder.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.action; 2 | 3 | import com.google.common.base.Joiner; 4 | import io.searchbox.params.Parameters; 5 | 6 | import java.util.Collection; 7 | import java.util.LinkedHashSet; 8 | import java.util.Set; 9 | 10 | /** 11 | * @author cihat keser 12 | */ 13 | @SuppressWarnings("unchecked") 14 | public abstract class AbstractMultiIndexActionBuilder extends AbstractAction.Builder { 15 | protected Set indexNames = new LinkedHashSet(); 16 | 17 | public K addIndex(String indexName) { 18 | this.indexNames.add(indexName); 19 | return (K) this; 20 | } 21 | 22 | public K addIndices(Collection indexNames) { 23 | this.indexNames.addAll(indexNames); 24 | return (K) this; 25 | } 26 | 27 | /** 28 | * Ignore unavailable indices, this includes indices that not exists or closed indices. 29 | * @param ignore whether to ignore unavailable indices 30 | */ 31 | public K ignoreUnavailable(boolean ignore) { 32 | setParameter(Parameters.IGNORE_UNAVAILABLE, String.valueOf(ignore)); 33 | return (K) this; 34 | } 35 | 36 | /** 37 | * Fail of wildcard indices expressions results into no concrete indices. 38 | * @param allow whether to allow no indices. 39 | */ 40 | public K allowNoIndices(boolean allow) { 41 | setParameter(Parameters.ALLOW_NO_INDICES, String.valueOf(allow)); 42 | return (K) this; 43 | } 44 | 45 | public String getJoinedIndices() { 46 | if (indexNames.size() > 0) { 47 | return Joiner.on(',').join(indexNames); 48 | } else { 49 | return "_all"; 50 | } 51 | } 52 | 53 | abstract public T build(); 54 | } 55 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/action/AbstractMultiTypeActionBuilder.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.action; 2 | 3 | import com.google.common.base.Joiner; 4 | 5 | import java.util.Collection; 6 | import java.util.LinkedHashSet; 7 | import java.util.Set; 8 | 9 | /** 10 | * @author cihat keser 11 | */ 12 | @SuppressWarnings("unchecked") 13 | public abstract class AbstractMultiTypeActionBuilder extends AbstractMultiIndexActionBuilder { 14 | private Set indexTypes = new LinkedHashSet(); 15 | 16 | public K addTypes(Collection indexTypes) { 17 | this.indexTypes.addAll(indexTypes); 18 | return (K) this; 19 | } 20 | 21 | public K addType(String indexType) { 22 | this.indexTypes.add(indexType); 23 | return (K) this; 24 | } 25 | 26 | public String getJoinedTypes() { 27 | return Joiner.on(',').join(indexTypes); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/action/Action.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.action; 2 | 3 | import com.google.gson.Gson; 4 | import io.searchbox.client.JestResult; 5 | import io.searchbox.client.config.ElasticsearchVersion; 6 | 7 | import java.util.Map; 8 | 9 | /** 10 | * @author Dogukan Sonmez 11 | */ 12 | public interface Action { 13 | 14 | String getRestMethodName(); 15 | 16 | String getURI(ElasticsearchVersion elasticsearchVersion); 17 | 18 | String getData(Gson gson); 19 | 20 | String getPathToResult(); 21 | 22 | Map getHeaders(); 23 | 24 | T createNewElasticSearchResult(String responseBody, int statusCode, String reasonPhrase, Gson gson); 25 | } 26 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/action/BulkableAction.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.action; 2 | 3 | import io.searchbox.client.JestResult; 4 | 5 | import java.util.Collection; 6 | 7 | /** 8 | * Represents an Action that can be included in a Bulk request. 9 | * 10 | * @author cihat keser 11 | */ 12 | public interface BulkableAction extends DocumentTargetedAction { 13 | 14 | String getBulkMethodName(); 15 | 16 | Collection getParameter(String key); 17 | 18 | } 19 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/action/DocumentTargetedAction.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.action; 2 | 3 | import io.searchbox.client.JestResult; 4 | 5 | /** 6 | * Represents an Action that can (but NOT necessarily does) operate on a targeted single document on Elasticsearch. 7 | * 8 | * @author cihat keser 9 | */ 10 | public interface DocumentTargetedAction extends Action { 11 | 12 | String getIndex(); 13 | 14 | String getType(); 15 | 16 | String getId(); 17 | } 18 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/action/GenericResultAbstractAction.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.action; 2 | 3 | import com.google.gson.Gson; 4 | import io.searchbox.client.JestResult; 5 | 6 | /** 7 | * @author cihat keser 8 | */ 9 | public abstract class GenericResultAbstractAction extends AbstractAction { 10 | 11 | public GenericResultAbstractAction() { 12 | } 13 | 14 | public GenericResultAbstractAction(Builder builder) { 15 | super(builder); 16 | } 17 | 18 | @Override 19 | public JestResult createNewElasticSearchResult(String responseBody, int statusCode, String reasonPhrase, Gson gson) { 20 | return createNewElasticSearchResult(new JestResult(gson), responseBody, statusCode, reasonPhrase, gson); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/action/GenericResultAbstractDocumentTargetedAction.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.action; 2 | 3 | import com.google.gson.Gson; 4 | import io.searchbox.client.JestResult; 5 | 6 | /** 7 | * @author cihat keser 8 | */ 9 | public abstract class GenericResultAbstractDocumentTargetedAction extends AbstractDocumentTargetedAction { 10 | 11 | public GenericResultAbstractDocumentTargetedAction(Builder builder) { 12 | super(builder); 13 | } 14 | 15 | @Override 16 | public JestResult createNewElasticSearchResult(String responseBody, int statusCode, String reasonPhrase, Gson gson) { 17 | return createNewElasticSearchResult(new JestResult(gson), responseBody, statusCode, reasonPhrase, gson); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/action/SingleResultAbstractDocumentTargetedAction.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.action; 2 | 3 | import com.google.gson.Gson; 4 | import io.searchbox.core.DocumentResult; 5 | 6 | /** 7 | * @author Bartosz Polnik 8 | */ 9 | public abstract class SingleResultAbstractDocumentTargetedAction extends AbstractDocumentTargetedAction { 10 | public SingleResultAbstractDocumentTargetedAction(Builder builder) { 11 | super(builder); 12 | } 13 | 14 | @Override 15 | public DocumentResult createNewElasticSearchResult(String responseBody, int statusCode, String reasonPhrase, Gson gson) { 16 | return createNewElasticSearchResult(new DocumentResult(gson), responseBody, statusCode, reasonPhrase, gson); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/annotations/JestId.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.annotations; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /** 9 | * @author Dogukan Sonmez 10 | */ 11 | 12 | 13 | @Target(value = ElementType.FIELD) 14 | @Retention(RetentionPolicy.RUNTIME) 15 | public @interface JestId { 16 | } 17 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/annotations/JestVersion.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.annotations; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /** 9 | * @author Sebastian Hilbig 10 | */ 11 | 12 | 13 | @Target(value = ElementType.FIELD) 14 | @Retention(RetentionPolicy.RUNTIME) 15 | public @interface JestVersion { 16 | } 17 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/client/JestClient.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.client; 2 | 3 | 4 | import io.searchbox.action.Action; 5 | 6 | import java.io.Closeable; 7 | import java.io.IOException; 8 | import java.util.Set; 9 | 10 | 11 | /** 12 | * @author Dogukan Sonmez 13 | */ 14 | public interface JestClient extends Closeable { 15 | 16 | T execute(Action clientRequest) throws IOException; 17 | 18 | void executeAsync(Action clientRequest, JestResultHandler jestResultHandler); 19 | 20 | /** 21 | * @deprecated Use {@link #close()} instead. 22 | */ 23 | @Deprecated 24 | void shutdownClient(); 25 | 26 | void setServers(Set servers); 27 | } 28 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/client/JestResultHandler.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.client; 2 | 3 | /** 4 | * @author Dogukan Sonmez 5 | */ 6 | 7 | public interface JestResultHandler { 8 | 9 | void completed(T result); 10 | 11 | void failed(Exception ex); 12 | 13 | 14 | } 15 | 16 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/client/config/ElasticsearchVersion.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.client.config; 2 | 3 | public enum ElasticsearchVersion { 4 | 5 | UNKNOWN, 6 | V2, 7 | V55 8 | } 9 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/client/config/exception/CouldNotConnectException.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.client.config.exception; 2 | 3 | import java.io.IOException; 4 | 5 | /** 6 | * Wrapper for a the host address of an HTTPConnectException 7 | * @author Brian Harrington 8 | */ 9 | public class CouldNotConnectException extends IOException { 10 | 11 | private final String host; 12 | 13 | public CouldNotConnectException(String host, Throwable cause) { 14 | super("Could not connect to " + host, cause); 15 | this.host = host; 16 | } 17 | 18 | public String getHost() { 19 | return host; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/client/config/exception/NoServerConfiguredException.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.client.config.exception; 2 | 3 | /** 4 | * Exception that specified that the client has no 5 | * knowledge of an elasticsearch node to communicate with. 6 | * 7 | */ 8 | public class NoServerConfiguredException extends RuntimeException { 9 | 10 | static final long serialVersionUID = -7034897190745766912L; 11 | 12 | /** 13 | * Constructs a new runtime exception with the specified detail message. 14 | * 15 | * @param message the detail message. The detail message is saved for 16 | * later retrieval by the {@link #getMessage()} method. 17 | */ 18 | public NoServerConfiguredException(String message) { 19 | super(message); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/client/config/idle/ReapableConnectionManager.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.client.config.idle; 2 | 3 | import java.util.concurrent.TimeUnit; 4 | 5 | public interface ReapableConnectionManager { 6 | void closeIdleConnections(long idleTimeout, TimeUnit unit); 7 | } 8 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/cloning/CloneUtils.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.cloning; 2 | 3 | import com.google.gson.*; 4 | 5 | import java.util.Map; 6 | 7 | /** 8 | * This class is just a workaround for the non-public deepCopy methods in Gson. 9 | */ 10 | public class CloneUtils { 11 | public static JsonElement deepClone(JsonElement jsonElement) { 12 | if (jsonElement instanceof JsonObject) { 13 | return deepCloneObject(jsonElement); 14 | } else if (jsonElement instanceof JsonArray) { 15 | return deepCloneArray(jsonElement); 16 | } else if (jsonElement instanceof JsonPrimitive) { 17 | return jsonElement; 18 | } 19 | 20 | return JsonNull.INSTANCE; 21 | } 22 | 23 | private static JsonElement deepCloneObject(JsonElement jsonElement) { 24 | JsonObject jsonObject = (JsonObject) jsonElement; 25 | JsonObject result = new JsonObject(); 26 | 27 | for (Map.Entry entry : jsonObject.entrySet()) { 28 | result.add(entry.getKey(), deepClone(entry.getValue())); 29 | } 30 | 31 | return result; 32 | } 33 | 34 | private static JsonElement deepCloneArray(JsonElement jsonElement) { 35 | JsonArray jsonArray = (JsonArray) jsonElement; 36 | JsonArray result = new JsonArray(); 37 | 38 | for (JsonElement element : jsonArray) { 39 | result.add(deepClone(element)); 40 | } 41 | 42 | return result; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/cluster/GetSettings.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.cluster; 2 | 3 | import io.searchbox.action.AbstractAction; 4 | import io.searchbox.action.GenericResultAbstractAction; 5 | import io.searchbox.client.config.ElasticsearchVersion; 6 | 7 | /** 8 | * Retrieve cluster wide settings. 9 | * 10 | * @author cihat keser 11 | */ 12 | public class GetSettings extends GenericResultAbstractAction { 13 | 14 | protected GetSettings(Builder builder) { 15 | super(builder); 16 | } 17 | 18 | protected String buildURI(ElasticsearchVersion elasticsearchVersion) { 19 | return super.buildURI(elasticsearchVersion) + "/_cluster/settings"; 20 | } 21 | 22 | @Override 23 | public String getRestMethodName() { 24 | return "GET"; 25 | } 26 | 27 | public static class Builder extends AbstractAction.Builder { 28 | 29 | @Override 30 | public GetSettings build() { 31 | return new GetSettings(this); 32 | } 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/cluster/NodesShutdown.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.cluster; 2 | 3 | import io.searchbox.action.AbstractMultiINodeActionBuilder; 4 | import io.searchbox.action.GenericResultAbstractAction; 5 | import io.searchbox.client.config.ElasticsearchVersion; 6 | 7 | /** 8 | * @author Dogukan Sonmez 9 | * @author cihat keser 10 | */ 11 | public class NodesShutdown extends GenericResultAbstractAction { 12 | 13 | protected NodesShutdown(Builder builder) { 14 | super(builder); 15 | } 16 | 17 | @Override 18 | protected String buildURI(ElasticsearchVersion elasticsearchVersion) { 19 | return super.buildURI(elasticsearchVersion) + "/_nodes/" + 20 | nodes + 21 | "/_shutdown"; 22 | } 23 | 24 | @Override 25 | public String getRestMethodName() { 26 | return "POST"; 27 | } 28 | 29 | @Override 30 | public String getPathToResult() { 31 | return "nodes"; 32 | } 33 | 34 | public static class Builder extends AbstractMultiINodeActionBuilder { 35 | 36 | /** 37 | * By default, the shutdown will be executed after a 1 second delay (1s). 38 | * The delay can be customized by setting the delay parameter in a time value format. 39 | * 40 | * @param value e.g.: "1s" -> 1 second, "10m" -> 10 minutes 41 | */ 42 | public Builder delay(String value) { 43 | return setParameter("delay", value); 44 | } 45 | 46 | @Override 47 | public NodesShutdown build() { 48 | return new NodesShutdown(this); 49 | } 50 | } 51 | } -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/cluster/PendingClusterTasks.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.cluster; 2 | 3 | import io.searchbox.action.AbstractAction; 4 | import io.searchbox.action.GenericResultAbstractAction; 5 | import io.searchbox.client.config.ElasticsearchVersion; 6 | 7 | public class PendingClusterTasks extends GenericResultAbstractAction { 8 | protected PendingClusterTasks(Builder builder) { 9 | super(builder); 10 | } 11 | 12 | @Override 13 | protected String buildURI(ElasticsearchVersion elasticsearchVersion) { 14 | return super.buildURI(elasticsearchVersion) + "/_cluster/pending_tasks"; 15 | } 16 | 17 | @Override 18 | public String getRestMethodName() { 19 | return "GET"; 20 | } 21 | 22 | public static class Builder extends AbstractAction.Builder { 23 | @Override 24 | public PendingClusterTasks build() { 25 | return new PendingClusterTasks(this); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/cluster/Stats.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.cluster; 2 | 3 | import io.searchbox.action.AbstractMultiINodeActionBuilder; 4 | import io.searchbox.action.GenericResultAbstractAction; 5 | import io.searchbox.client.config.ElasticsearchVersion; 6 | 7 | public class Stats extends GenericResultAbstractAction { 8 | protected Stats(Builder builder) { 9 | super(builder); 10 | } 11 | 12 | @Override 13 | protected String buildURI(ElasticsearchVersion elasticsearchVersion) { 14 | return super.buildURI(elasticsearchVersion) + "/_cluster/stats/nodes/" + nodes; 15 | } 16 | 17 | @Override 18 | public String getRestMethodName() { 19 | return "GET"; 20 | } 21 | 22 | public static class Builder extends AbstractMultiINodeActionBuilder { 23 | @Override 24 | public Stats build() { 25 | return new Stats(this); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/cluster/TasksInformation.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.cluster; 2 | 3 | import io.searchbox.action.GenericResultAbstractAction; 4 | import io.searchbox.client.config.ElasticsearchVersion; 5 | 6 | /** 7 | * Currently only supports retrieving information for a particular task 8 | */ 9 | public class TasksInformation extends GenericResultAbstractAction { 10 | 11 | protected String task; 12 | 13 | protected TasksInformation(Builder builder) { 14 | super(builder); 15 | task = builder.task; 16 | } 17 | 18 | @Override 19 | protected String buildURI(ElasticsearchVersion elasticsearchVersion) { 20 | String uri = super.buildURI(elasticsearchVersion) + "_tasks"; 21 | if (task != null) { 22 | uri += "/" + task; 23 | } 24 | return uri; 25 | } 26 | 27 | @Override 28 | public String getRestMethodName() { 29 | return "GET"; 30 | } 31 | 32 | public static class Builder extends GenericResultAbstractAction.Builder { 33 | 34 | protected String task; 35 | 36 | public Builder task(String task) { 37 | this.task = task; 38 | return this; 39 | } 40 | 41 | @Override 42 | public TasksInformation build() { 43 | return new TasksInformation(this); 44 | } 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/cluster/reroute/RerouteAllocateReplica.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.cluster.reroute; 2 | 3 | import java.util.LinkedHashMap; 4 | import java.util.Map; 5 | 6 | public class RerouteAllocateReplica implements RerouteCommand { 7 | 8 | private final String index; 9 | private final int shard; 10 | private final String node; 11 | 12 | public RerouteAllocateReplica(String index, int shard, String node) { 13 | this.index = index; 14 | this.shard = shard; 15 | this.node = node; 16 | } 17 | 18 | @Override 19 | public String getType() { 20 | return "allocate_replica"; 21 | } 22 | 23 | @Override 24 | public Map getData() { 25 | Map paramsMap = new LinkedHashMap<>(); 26 | 27 | paramsMap.put("index", index); 28 | paramsMap.put("shard", shard); 29 | paramsMap.put("node", node); 30 | 31 | return paramsMap; 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/cluster/reroute/RerouteCancel.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.cluster.reroute; 2 | 3 | import java.util.LinkedHashMap; 4 | import java.util.Map; 5 | 6 | public class RerouteCancel implements RerouteCommand { 7 | 8 | private final String index; 9 | private final int shard; 10 | private final String node; 11 | private final boolean allowPrimary; 12 | 13 | public RerouteCancel(String index, int shard, String node, boolean allowPrimary) { 14 | this.index = index; 15 | this.shard = shard; 16 | this.node = node; 17 | this.allowPrimary = allowPrimary; 18 | } 19 | 20 | @Override 21 | public String getType() { 22 | return "cancel"; 23 | } 24 | 25 | @Override 26 | public Map getData() { 27 | Map paramsMap = new LinkedHashMap<>(); 28 | 29 | paramsMap.put("index", index); 30 | paramsMap.put("shard", shard); 31 | paramsMap.put("node", node); 32 | paramsMap.put("allow_primary", allowPrimary); 33 | 34 | return paramsMap; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/cluster/reroute/RerouteCommand.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.cluster.reroute; 2 | 3 | import java.util.Map; 4 | 5 | public interface RerouteCommand { 6 | String getType(); 7 | 8 | Map getData(); 9 | } 10 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/cluster/reroute/RerouteMove.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.cluster.reroute; 2 | 3 | 4 | import java.util.LinkedHashMap; 5 | import java.util.Map; 6 | 7 | public class RerouteMove implements RerouteCommand { 8 | 9 | private final String index; 10 | private final int shard; 11 | private final String fromNode; 12 | private final String toNode; 13 | 14 | public RerouteMove(String index, int shard, String fromNode, String toNode) { 15 | this.index = index; 16 | this.shard = shard; 17 | this.fromNode = fromNode; 18 | this.toNode = toNode; 19 | } 20 | 21 | @Override 22 | public String getType() { 23 | return "move"; 24 | } 25 | 26 | @Override 27 | public Map getData() { 28 | Map paramsMap = new LinkedHashMap(); 29 | paramsMap.put("index", index); 30 | paramsMap.put("shard", shard); 31 | paramsMap.put("from_node", fromNode); 32 | paramsMap.put("to_node", toNode); 33 | 34 | return paramsMap; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/core/ClearScroll.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.core; 2 | 3 | import com.google.common.collect.ImmutableMap; 4 | import io.searchbox.action.GenericResultAbstractAction; 5 | import io.searchbox.client.config.ElasticsearchVersion; 6 | 7 | import java.util.Collection; 8 | import java.util.LinkedHashSet; 9 | import java.util.Set; 10 | 11 | 12 | public class ClearScroll extends GenericResultAbstractAction { 13 | 14 | private final String uri; 15 | 16 | public ClearScroll(Builder builder) { 17 | 18 | if (builder.getScrollIds().size() == 0) { 19 | uri = "/_search/scroll/_all"; 20 | this.payload = null; 21 | } else { 22 | uri = "/_search/scroll"; 23 | this.payload = ImmutableMap.of("scroll_id", builder.getScrollIds()); 24 | } 25 | } 26 | 27 | @Override 28 | public String getRestMethodName() { 29 | return "DELETE"; 30 | } 31 | 32 | @Override 33 | protected String buildURI(ElasticsearchVersion elasticsearchVersion) { 34 | return super.buildURI(elasticsearchVersion) + uri; 35 | } 36 | 37 | public static class Builder extends GenericResultAbstractAction.Builder { 38 | 39 | protected Collection scrollIds = new LinkedHashSet(); 40 | 41 | public Builder addScrollId(String scrollId) { 42 | this.scrollIds.add(scrollId); 43 | return this; 44 | } 45 | 46 | public Builder addScrollIds(Set scrollIds) { 47 | this.scrollIds.addAll(scrollIds); 48 | return this; 49 | } 50 | 51 | @Override 52 | public ClearScroll build() { 53 | return new ClearScroll(this); 54 | } 55 | 56 | public Collection getScrollIds() { 57 | return scrollIds; 58 | } 59 | 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/core/Count.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.core; 2 | 3 | import com.google.gson.Gson; 4 | import io.searchbox.action.AbstractAction; 5 | import io.searchbox.action.AbstractMultiTypeActionBuilder; 6 | import io.searchbox.client.config.ElasticsearchVersion; 7 | 8 | /** 9 | * @author Dogukan Sonmez 10 | * @author cihat keser 11 | */ 12 | public class Count extends AbstractAction { 13 | 14 | protected Count(Builder builder) { 15 | super(builder); 16 | this.payload = builder.query; 17 | } 18 | 19 | @Override 20 | protected String buildURI(ElasticsearchVersion elasticsearchVersion) { 21 | return super.buildURI(elasticsearchVersion) + "/_count"; 22 | } 23 | 24 | @Override 25 | public String getPathToResult() { 26 | return "count"; 27 | } 28 | 29 | @Override 30 | public CountResult createNewElasticSearchResult(String responseBody, int statusCode, String reasonPhrase, Gson gson) { 31 | return createNewElasticSearchResult(new CountResult(gson), responseBody, statusCode, reasonPhrase, gson); 32 | } 33 | 34 | @Override 35 | public String getRestMethodName() { 36 | return "POST"; 37 | } 38 | 39 | public static class Builder extends AbstractMultiTypeActionBuilder { 40 | private String query; 41 | 42 | public Builder query(String query) { 43 | this.query = query; 44 | return this; 45 | } 46 | 47 | @Override 48 | public Count build() { 49 | return new Count(this); 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/core/CountResult.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.core; 2 | 3 | import com.google.gson.Gson; 4 | import io.searchbox.client.JestResult; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * @author cihat.keser 10 | */ 11 | public class CountResult extends JestResult { 12 | 13 | public CountResult(CountResult countResult) { 14 | super(countResult); 15 | } 16 | 17 | public CountResult(Gson gson) { 18 | super(gson); 19 | } 20 | 21 | @Override 22 | @Deprecated 23 | public T getSourceAsObject(Class clazz) { 24 | return super.getSourceAsObject(clazz); 25 | } 26 | 27 | @Override 28 | @Deprecated 29 | public List getSourceAsObjectList(Class type) { 30 | return super.getSourceAsObjectList(type); 31 | } 32 | 33 | public Double getCount() { 34 | Double count = null; 35 | 36 | if (isSucceeded) { 37 | count = getSourceAsObject(Double.class); 38 | } 39 | 40 | return count; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/core/Delete.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.core; 2 | 3 | import io.searchbox.action.BulkableAction; 4 | import io.searchbox.action.SingleResultAbstractDocumentTargetedAction; 5 | 6 | /** 7 | * @author Dogukan Sonmez 8 | * @author cihat keser 9 | */ 10 | public class Delete extends SingleResultAbstractDocumentTargetedAction implements BulkableAction { 11 | 12 | protected Delete(Builder builder) { 13 | super(builder); 14 | } 15 | 16 | @Override 17 | public String getRestMethodName() { 18 | return "DELETE"; 19 | } 20 | 21 | @Override 22 | public String getPathToResult() { 23 | return "ok"; 24 | } 25 | 26 | @Override 27 | public String getBulkMethodName() { 28 | return "delete"; 29 | } 30 | 31 | public static class Builder extends SingleResultAbstractDocumentTargetedAction.Builder { 32 | 33 | public Builder(String id) { 34 | this.id(id); 35 | } 36 | 37 | public Delete build() { 38 | return new Delete(this); 39 | } 40 | 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/core/DeleteByQuery.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.core; 2 | 3 | import io.searchbox.action.AbstractMultiTypeActionBuilder; 4 | import io.searchbox.action.GenericResultAbstractAction; 5 | import io.searchbox.client.config.ElasticsearchVersion; 6 | 7 | /** 8 | * Delete By Query API is removed in Elasticsearch version 2.0. 9 | * You need to install the plugin with the same name for this action to work. 10 | * 11 | * @author Dogukan Sonmez 12 | * @author cihat keser 13 | * @see Delete By Query is now a plugin 14 | */ 15 | public class DeleteByQuery extends GenericResultAbstractAction { 16 | 17 | protected DeleteByQuery(Builder builder) { 18 | super(builder); 19 | 20 | this.payload = builder.query; 21 | } 22 | 23 | @Override 24 | protected String buildURI(ElasticsearchVersion elasticsearchVersion) { 25 | return super.buildURI(elasticsearchVersion) + "/_delete_by_query"; 26 | } 27 | 28 | @Override 29 | public String getPathToResult() { 30 | return "ok"; 31 | } 32 | 33 | @Override 34 | public String getRestMethodName() { 35 | return "POST"; 36 | } 37 | 38 | public static class Builder extends AbstractMultiTypeActionBuilder { 39 | 40 | private String query; 41 | 42 | public Builder(String query) { 43 | this.query = query; 44 | } 45 | 46 | @Override 47 | public DeleteByQuery build() { 48 | return new DeleteByQuery(this); 49 | } 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/core/DocumentResult.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.core; 2 | 3 | import com.google.gson.Gson; 4 | import com.google.gson.JsonElement; 5 | import io.searchbox.client.JestResult; 6 | 7 | /** 8 | * @author Bartosz Polnik 9 | */ 10 | public class DocumentResult extends JestResult { 11 | public DocumentResult(Gson gson) { 12 | super(gson); 13 | } 14 | 15 | public String getIndex() { 16 | return getAsString(jsonObject.get("_index")); 17 | } 18 | 19 | public String getType() { 20 | return getAsString(jsonObject.get("_type")); 21 | } 22 | 23 | public String getId() { 24 | return getAsString(jsonObject.get("_id")); 25 | } 26 | 27 | public Long getVersion() { 28 | return getAsLong(jsonObject.get("_version")); 29 | } 30 | 31 | private String getAsString(JsonElement jsonElement) { 32 | if(jsonElement == null) { 33 | return null; 34 | } else { 35 | return jsonElement.getAsString(); 36 | } 37 | } 38 | 39 | private Long getAsLong(JsonElement jsonElement) { 40 | if(jsonElement == null) { 41 | return null; 42 | } else { 43 | return jsonElement.getAsLong(); 44 | } 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/core/Explain.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.core; 2 | 3 | import io.searchbox.action.SingleResultAbstractDocumentTargetedAction; 4 | import io.searchbox.client.config.ElasticsearchVersion; 5 | 6 | /** 7 | * @author Dogukan Sonmez 8 | * @author cihat keser 9 | */ 10 | public class Explain extends SingleResultAbstractDocumentTargetedAction { 11 | 12 | protected Explain(Builder builder) { 13 | super(builder); 14 | this.payload = builder.query; 15 | } 16 | 17 | @Override 18 | public String getRestMethodName() { 19 | return "POST"; 20 | } 21 | 22 | @Override 23 | protected String buildURI(ElasticsearchVersion elasticsearchVersion) { 24 | return super.buildURI(elasticsearchVersion) + "/_explain"; 25 | } 26 | 27 | public static class Builder extends SingleResultAbstractDocumentTargetedAction.Builder { 28 | private final Object query; 29 | 30 | public Builder(String index, String type, String id, Object query) { 31 | this.index(index); 32 | this.type(type); 33 | this.id(id); 34 | this.query = query; 35 | } 36 | 37 | public Explain build() { 38 | return new Explain(this); 39 | } 40 | 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/core/Get.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.core; 2 | 3 | import io.searchbox.action.SingleResultAbstractDocumentTargetedAction; 4 | 5 | 6 | /** 7 | * @author Dogukan Sonmez 8 | * @author cihat keser 9 | */ 10 | public class Get extends SingleResultAbstractDocumentTargetedAction { 11 | 12 | protected Get(Builder builder) { 13 | super(builder); 14 | } 15 | 16 | @Override 17 | public String getRestMethodName() { 18 | return "GET"; 19 | } 20 | 21 | @Override 22 | public String getPathToResult() { 23 | return "_source"; 24 | } 25 | 26 | public static class Builder extends SingleResultAbstractDocumentTargetedAction.Builder { 27 | 28 | /** 29 | * Index and ID parameters are mandatory but type is optional (_all will be used for type if left blank). 30 | *

31 | * The get API allows for _type to be optional. Set it to _all in order to fetch the 32 | * first document matching the id across all types. 33 | */ 34 | public Builder(String index, String id) { 35 | this.index(index); 36 | this.id(id); 37 | this.type("_all"); 38 | } 39 | 40 | public Get build() { 41 | return new Get(this); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/core/Index.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.core; 2 | 3 | import io.searchbox.action.BulkableAction; 4 | import io.searchbox.action.SingleResultAbstractDocumentTargetedAction; 5 | import io.searchbox.params.Parameters; 6 | 7 | import java.util.Collection; 8 | 9 | /** 10 | * @author Dogukan Sonmez 11 | * @author cihat keser 12 | */ 13 | public class Index extends SingleResultAbstractDocumentTargetedAction implements BulkableAction { 14 | 15 | protected Index(Builder builder) { 16 | super(builder); 17 | this.payload = builder.source; 18 | } 19 | 20 | @Override 21 | public String getPathToResult() { 22 | return "ok"; 23 | } 24 | 25 | @Override 26 | public String getRestMethodName() { 27 | return (id != null) ? "PUT" : "POST"; 28 | } 29 | 30 | @Override 31 | public String getBulkMethodName() { 32 | Collection opType = getParameter(Parameters.OP_TYPE); 33 | if (opType != null) { 34 | if (opType.size() > 1) { 35 | throw new IllegalArgumentException("Expecting a single value for OP_TYPE parameter, you provided: " + opType.size()); 36 | } 37 | return (opType.size() == 1 && ((opType.iterator().next()).toString().equalsIgnoreCase("create"))) ? "create" : "index"; 38 | } else { 39 | return "index"; 40 | } 41 | } 42 | 43 | public static class Builder extends SingleResultAbstractDocumentTargetedAction.Builder { 44 | private final Object source; 45 | 46 | public Builder(Object source) { 47 | this.source = source; 48 | this.id(getIdFromSource(source)); // set the default for id if it exists in source 49 | } 50 | 51 | public Index build() { 52 | return new Index(this); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/core/Ping.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.core; 2 | 3 | import io.searchbox.action.GenericResultAbstractAction; 4 | import io.searchbox.client.config.ElasticsearchVersion; 5 | 6 | public class Ping extends GenericResultAbstractAction { 7 | protected Ping(Builder builder) { 8 | super(builder); 9 | } 10 | 11 | @Override 12 | protected String buildURI(ElasticsearchVersion elasticsearchVersion) { 13 | return super.buildURI(elasticsearchVersion); 14 | } 15 | 16 | @Override 17 | public String getRestMethodName() { 18 | return "GET"; 19 | } 20 | 21 | public static class Builder extends GenericResultAbstractAction.Builder { 22 | public Ping build() { 23 | return new Ping(this); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/core/Validate.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.core; 2 | 3 | import io.searchbox.action.GenericResultAbstractAction; 4 | import io.searchbox.client.config.ElasticsearchVersion; 5 | 6 | /** 7 | * @author Dogukan Sonmez 8 | * @author cihat keser 9 | */ 10 | public class Validate extends GenericResultAbstractAction { 11 | 12 | protected Validate(Builder builder) { 13 | super(builder); 14 | 15 | this.indexName = builder.index; 16 | this.typeName = builder.type; 17 | this.payload = builder.query; 18 | } 19 | 20 | @Override 21 | protected String buildURI(ElasticsearchVersion elasticsearchVersion) { 22 | return super.buildURI(elasticsearchVersion) + "/_validate/query"; 23 | } 24 | 25 | @Override 26 | public String getRestMethodName() { 27 | return "POST"; 28 | } 29 | 30 | @Override 31 | public String getPathToResult() { 32 | return "valid"; 33 | } 34 | 35 | public static class Builder extends GenericResultAbstractAction.Builder { 36 | private final Object query; 37 | private String index; 38 | private String type; 39 | 40 | public Builder(Object query) { 41 | this.query = query; 42 | } 43 | 44 | public Builder index(String val) { 45 | index = val; 46 | return this; 47 | } 48 | 49 | public Builder type(String val) { 50 | type = val; 51 | return this; 52 | } 53 | 54 | public Validate build() { 55 | return new Validate(this); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/core/search/aggregation/Aggregation.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.core.search.aggregation; 2 | 3 | import com.google.gson.JsonObject; 4 | 5 | import java.util.Objects; 6 | 7 | /** 8 | * @author cfstout 9 | */ 10 | 11 | public abstract class Aggregation { 12 | 13 | protected String name; 14 | protected JsonObject jsonRoot; 15 | 16 | public Aggregation(String name, JsonObject jsonRoot) { 17 | this.name = name; 18 | this.jsonRoot = jsonRoot; 19 | } 20 | 21 | public String getName() { 22 | return name; 23 | } 24 | 25 | @Override 26 | public boolean equals(Object obj) { 27 | if (obj == null) { 28 | return false; 29 | } 30 | if (obj == this) { 31 | return true; 32 | } 33 | if (obj.getClass() != getClass()) { 34 | return false; 35 | } 36 | Aggregation rhs = (Aggregation) obj; 37 | return Objects.equals(name, rhs.name); 38 | } 39 | 40 | @Override 41 | public int hashCode() { 42 | return Objects.hash(name); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/core/search/aggregation/AggregationField.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.core.search.aggregation; 2 | 3 | /** 4 | * @author cfstout 5 | */ 6 | public enum AggregationField { 7 | VALUE("value"), 8 | BUCKETS("buckets"), 9 | KEY("key"), //Can be String or Long 10 | KEY_AS_STRING("key_as_string"), 11 | DOC_COUNT("doc_count"), 12 | FROM("from"), 13 | TO("to"), 14 | FROM_AS_STRING("from_as_string"), 15 | TO_AS_STRING("to_as_string"), 16 | SUM_OF_SQUARES("sum_of_squares"), 17 | VARIANCE("variance"), 18 | STD_DEVIATION("std_deviation"), 19 | BOUNDS("bounds"), 20 | TOP_LEFT("top_left"), 21 | BOTTOM_RIGHT("bottom_right"), 22 | LAT("lat"), 23 | LON("lon"), 24 | UNIT("unit"), 25 | VALUES("values"), 26 | SCORE("score"), 27 | BG_COUNT("bg_count"), //Background Count 28 | COUNT("count"), 29 | MIN("min"), 30 | MAX("max"), 31 | AVG("avg"), 32 | SUM("sum"), 33 | DOC_COUNT_ERROR_UPPER_BOUND("doc_count_error_upper_bound"), 34 | SUM_OTHER_DOC_COUNT("sum_other_doc_count"), 35 | AFTER_KEY("after_key"); 36 | 37 | private final String field; 38 | 39 | AggregationField(String s) { 40 | field = s; 41 | } 42 | 43 | public String toString() { 44 | return field; 45 | } 46 | 47 | public boolean equals(String s) { 48 | return s.equals(toString()); 49 | } 50 | } 51 | 52 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/core/search/aggregation/AvgAggregation.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.core.search.aggregation; 2 | 3 | import com.google.gson.JsonObject; 4 | 5 | /** 6 | * @author cfstout 7 | */ 8 | public class AvgAggregation extends SingleValueAggregation { 9 | 10 | public static final String TYPE = "avg"; 11 | 12 | public AvgAggregation(String name, JsonObject avgAggregation) { 13 | super(name, avgAggregation); 14 | } 15 | 16 | /** 17 | * @return Average if it was found and not null, null otherwise 18 | */ 19 | public Double getAvg() { 20 | return getValue(); 21 | } 22 | 23 | @Override 24 | public boolean equals(Object obj) { 25 | if (obj == null) { 26 | return false; 27 | } 28 | if (obj == this) { 29 | return true; 30 | } 31 | if (obj.getClass() != getClass()) { 32 | return false; 33 | } 34 | 35 | return super.equals(obj); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/core/search/aggregation/Bucket.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.core.search.aggregation; 2 | 3 | import com.google.gson.JsonObject; 4 | 5 | import java.util.Objects; 6 | 7 | /** 8 | * @author cfstout 9 | */ 10 | public abstract class Bucket extends MetricAggregation { 11 | 12 | protected Long count; 13 | 14 | public Bucket(JsonObject bucketRoot, Long count) { 15 | this("bucket", bucketRoot, count); 16 | } 17 | 18 | public Bucket(String name, JsonObject bucketRoot, Long count) { 19 | super(name, bucketRoot); 20 | this.count = count; 21 | } 22 | 23 | public Long getCount() { 24 | return count; 25 | } 26 | 27 | @Override 28 | public boolean equals(Object obj) { 29 | if (obj == null) { 30 | return false; 31 | } 32 | if (obj == this) { 33 | return true; 34 | } 35 | if (obj.getClass() != getClass()) { 36 | return false; 37 | } 38 | Bucket rhs = (Bucket) obj; 39 | return super.equals(obj) && Objects.equals(count, rhs.count); 40 | } 41 | 42 | @Override 43 | public int hashCode() { 44 | return Objects.hash(super.hashCode(), count); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/core/search/aggregation/BucketAggregation.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.core.search.aggregation; 2 | 3 | import com.google.gson.JsonObject; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * @author cfstout 9 | */ 10 | public abstract class BucketAggregation extends Aggregation { 11 | 12 | public BucketAggregation(String name, JsonObject root) { 13 | super(name, root); 14 | } 15 | 16 | public abstract List getBuckets(); 17 | } 18 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/core/search/aggregation/CardinalityAggregation.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.core.search.aggregation; 2 | 3 | import com.google.gson.JsonObject; 4 | 5 | import java.util.Objects; 6 | 7 | import static io.searchbox.core.search.aggregation.AggregationField.VALUE; 8 | 9 | /** 10 | * @author cfstout 11 | */ 12 | public class CardinalityAggregation extends MetricAggregation { 13 | 14 | public static final String TYPE = "cardinality"; 15 | 16 | private Long cardinality; 17 | 18 | public CardinalityAggregation(String name, JsonObject cardinalityAggregation) { 19 | super(name, cardinalityAggregation); 20 | if(cardinalityAggregation.has(String.valueOf(VALUE)) && !cardinalityAggregation.get(String.valueOf(VALUE)).isJsonNull()) { 21 | cardinality = cardinalityAggregation.get(String.valueOf(VALUE)).getAsLong(); 22 | } 23 | } 24 | 25 | /** 26 | * @return Cardinality 27 | */ 28 | public Long getCardinality() { 29 | return cardinality; 30 | } 31 | 32 | @Override 33 | public boolean equals(Object obj) { 34 | if (obj == null) { 35 | return false; 36 | } 37 | if (obj == this) { 38 | return true; 39 | } 40 | if (obj.getClass() != getClass()) { 41 | return false; 42 | } 43 | 44 | CardinalityAggregation rhs = (CardinalityAggregation) obj; 45 | return super.equals(obj) && Objects.equals(cardinality, rhs.cardinality); 46 | } 47 | 48 | @Override 49 | public int hashCode() { 50 | return Objects.hash(super.hashCode(), cardinality); 51 | } 52 | } 53 | 54 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/core/search/aggregation/ChildrenAggregation.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.core.search.aggregation; 2 | 3 | import com.google.gson.JsonObject; 4 | 5 | public class ChildrenAggregation extends MetricAggregation { 6 | 7 | protected String name; 8 | protected JsonObject jsonRoot; 9 | public static final String TYPE = "child"; 10 | 11 | public ChildrenAggregation(String name, JsonObject childrenAggregation) { 12 | 13 | super(name, childrenAggregation); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/core/search/aggregation/FilterAggregation.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.core.search.aggregation; 2 | 3 | import com.google.gson.JsonObject; 4 | 5 | import java.util.Objects; 6 | 7 | import static io.searchbox.core.search.aggregation.AggregationField.DOC_COUNT; 8 | 9 | /** 10 | * @author cfstout 11 | */ 12 | public class FilterAggregation extends Bucket { 13 | 14 | public static final String TYPE = "filter"; 15 | 16 | public FilterAggregation(String name, JsonObject filterAggregation) { 17 | super(name, filterAggregation, filterAggregation.get(String.valueOf(DOC_COUNT)).getAsLong()); 18 | } 19 | 20 | @Override 21 | public int hashCode() { 22 | return Objects.hash(super.hashCode(), TYPE); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/core/search/aggregation/MaxAggregation.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.core.search.aggregation; 2 | 3 | import com.google.gson.JsonObject; 4 | 5 | import java.util.Objects; 6 | 7 | /** 8 | * @author cfstout 9 | */ 10 | public class MaxAggregation extends SingleValueAggregation { 11 | 12 | public static final String TYPE = "max"; 13 | 14 | public MaxAggregation(String name, JsonObject maxAggregation) { 15 | super(name, maxAggregation); 16 | } 17 | 18 | /** 19 | * @return Max if it was found and not null, null otherwise 20 | */ 21 | public Double getMax() { 22 | return getValue(); 23 | } 24 | 25 | 26 | @Override 27 | public int hashCode() { 28 | return Objects.hash(super.hashCode(), TYPE); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/core/search/aggregation/MinAggregation.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.core.search.aggregation; 2 | 3 | import com.google.gson.JsonObject; 4 | 5 | import java.util.Objects; 6 | 7 | /** 8 | * @author cfstout 9 | */ 10 | public class MinAggregation extends SingleValueAggregation { 11 | 12 | public static final String TYPE = "min"; 13 | 14 | public MinAggregation(String name, JsonObject minAggregation) { 15 | super(name, minAggregation); 16 | } 17 | 18 | /** 19 | * @return Min if it was found and not null, null otherwise 20 | */ 21 | public Double getMin() { 22 | return getValue(); 23 | } 24 | 25 | @Override 26 | public int hashCode() { 27 | return Objects.hash(super.hashCode(), TYPE); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/core/search/aggregation/MissingAggregation.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.core.search.aggregation; 2 | 3 | import com.google.gson.JsonObject; 4 | 5 | import java.util.Objects; 6 | 7 | import static io.searchbox.core.search.aggregation.AggregationField.DOC_COUNT; 8 | 9 | /** 10 | * @author cfstout 11 | */ 12 | 13 | public class MissingAggregation extends MetricAggregation { 14 | public static final String TYPE = "missing"; 15 | 16 | private Long missing; 17 | 18 | public MissingAggregation(String name, JsonObject missingAggregation) { 19 | super(name, missingAggregation); 20 | missing = missingAggregation.get(String.valueOf(DOC_COUNT)).getAsLong(); 21 | } 22 | 23 | public Long getMissing() { 24 | return missing; 25 | } 26 | 27 | 28 | 29 | @Override 30 | public boolean equals(Object obj) { 31 | if (obj == null) { 32 | return false; 33 | } 34 | if (obj == this) { 35 | return true; 36 | } 37 | if (obj.getClass() != getClass()) { 38 | return false; 39 | } 40 | 41 | MissingAggregation rhs = (MissingAggregation) obj; 42 | return super.equals(obj) && Objects.equals(missing, rhs.missing); 43 | } 44 | 45 | @Override 46 | public int hashCode() { 47 | return Objects.hash(super.hashCode(), missing); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/core/search/aggregation/PercentileRanksAggregation.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.core.search.aggregation; 2 | 3 | import com.google.gson.JsonElement; 4 | import com.google.gson.JsonObject; 5 | 6 | import java.util.HashMap; 7 | import java.util.Map; 8 | import java.util.Objects; 9 | 10 | import static io.searchbox.core.search.aggregation.AggregationField.VALUES; 11 | 12 | /** 13 | * @author cfstout 14 | */ 15 | public class PercentileRanksAggregation extends MetricAggregation { 16 | 17 | public static final String TYPE = "percentile_ranks"; 18 | 19 | private Map percentileRanks = new HashMap(); 20 | 21 | public PercentileRanksAggregation(String name, JsonObject percentilesAggregation) { 22 | super(name, percentilesAggregation); 23 | parseSource(percentilesAggregation.getAsJsonObject(String.valueOf(VALUES))); 24 | } 25 | 26 | private void parseSource(JsonObject source) { 27 | for (Map.Entry entry : source.entrySet()) { 28 | if (!(Double.isNaN(entry.getValue().getAsDouble()))) { 29 | percentileRanks.put(entry.getKey(), entry.getValue().getAsDouble()); 30 | } 31 | } 32 | } 33 | 34 | public Map getPercentileRanks() { 35 | return percentileRanks; 36 | } 37 | 38 | @Override 39 | public boolean equals(Object obj) { 40 | if (obj == null) { 41 | return false; 42 | } 43 | if (obj == this) { 44 | return true; 45 | } 46 | if (obj.getClass() != getClass()) { 47 | return false; 48 | } 49 | 50 | PercentileRanksAggregation rhs = (PercentileRanksAggregation) obj; 51 | return super.equals(obj) && Objects.equals(percentileRanks, rhs.percentileRanks); 52 | } 53 | 54 | @Override 55 | public int hashCode() { 56 | return Objects.hash(super.hashCode(), percentileRanks); 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/core/search/aggregation/PercentilesAggregation.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.core.search.aggregation; 2 | 3 | import com.google.gson.JsonElement; 4 | import com.google.gson.JsonObject; 5 | 6 | import java.util.HashMap; 7 | import java.util.Map; 8 | import java.util.Objects; 9 | 10 | /** 11 | * @author cfstout 12 | */ 13 | public class PercentilesAggregation extends MetricAggregation { 14 | 15 | public static final String TYPE = "percentiles"; 16 | 17 | private Map percentiles = new HashMap(); 18 | 19 | public PercentilesAggregation(String name, JsonObject percentilesAggregation) { 20 | super(name, percentilesAggregation); 21 | parseSource(percentilesAggregation.getAsJsonObject(String.valueOf(AggregationField.VALUES))); 22 | } 23 | 24 | private void parseSource(JsonObject source) { 25 | for (Map.Entry entry : source.entrySet()) { 26 | if(!(Double.isNaN(entry.getValue().getAsDouble()))) { 27 | percentiles.put(entry.getKey(), entry.getValue().getAsDouble()); 28 | } 29 | } 30 | } 31 | 32 | public Map getPercentiles() { 33 | return percentiles; 34 | } 35 | 36 | @Override 37 | public boolean equals(Object obj) { 38 | if (obj == null) { 39 | return false; 40 | } 41 | if (obj == this) { 42 | return true; 43 | } 44 | if (obj.getClass() != getClass()) { 45 | return false; 46 | } 47 | 48 | PercentilesAggregation rhs = (PercentilesAggregation) obj; 49 | return super.equals(obj) && Objects.equals(percentiles, rhs.percentiles); 50 | } 51 | 52 | @Override 53 | public int hashCode() { 54 | return Objects.hash(super.hashCode(), percentiles); 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/core/search/aggregation/Range.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.core.search.aggregation; 2 | 3 | import com.google.gson.JsonObject; 4 | 5 | import java.util.Objects; 6 | 7 | /** 8 | * Represents data range defined by two limits (a lower limit called from and an upper limit called to) in a bucket. 9 | */ 10 | public class Range extends Bucket { 11 | private Double from = Double.NEGATIVE_INFINITY; 12 | private Double to = Double.POSITIVE_INFINITY; 13 | 14 | public Range(JsonObject bucket, Double from, Double to, Long count) { 15 | super(bucket, count); 16 | this.from = from; 17 | this.to = to; 18 | } 19 | 20 | public Double getFrom() { 21 | return from; 22 | } 23 | 24 | public Double getTo() { 25 | return to; 26 | } 27 | 28 | @Override 29 | public boolean equals(Object o) { 30 | if (this == o) { 31 | return true; 32 | } 33 | if (o == null || getClass() != o.getClass()) { 34 | return false; 35 | } 36 | 37 | Range rhs = (Range) o; 38 | return Objects.equals(count, rhs.count) 39 | && Objects.equals(from, rhs.from) 40 | && Objects.equals(to, rhs.to); 41 | } 42 | 43 | @Override 44 | public int hashCode() { 45 | return Objects.hash(count, from, to); 46 | } 47 | } -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/core/search/aggregation/RootAggregation.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.core.search.aggregation; 2 | 3 | import com.google.gson.JsonObject; 4 | 5 | import java.util.Objects; 6 | 7 | /** 8 | * Place holder class used to represent the root aggregation 9 | * returned to the user for processing. 10 | * 11 | * @author cfstout 12 | */ 13 | public class RootAggregation extends MetricAggregation { 14 | 15 | public RootAggregation(String name, JsonObject root) { 16 | super(name, root); 17 | } 18 | 19 | 20 | @Override 21 | public int hashCode() { 22 | return Objects.hash(super.hashCode(), "root"); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/core/search/aggregation/ScriptedMetricAggregation.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.core.search.aggregation; 2 | 3 | import com.google.gson.JsonObject; 4 | 5 | import java.util.Objects; 6 | 7 | /** 8 | * @author cfstout 9 | */ 10 | public class ScriptedMetricAggregation extends SingleValueAggregation { 11 | 12 | public static final String TYPE = "scripted_metric"; 13 | 14 | public ScriptedMetricAggregation(String name, JsonObject scriptedMetricAggregation) { 15 | super(name, scriptedMetricAggregation); 16 | } 17 | 18 | public Double getScriptedMetric() { 19 | return getValue(); 20 | } 21 | 22 | @Override 23 | public int hashCode() { 24 | return Objects.hash(super.hashCode(), TYPE); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/core/search/aggregation/SingleValueAggregation.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.core.search.aggregation; 2 | 3 | import com.google.gson.JsonObject; 4 | 5 | import java.util.Objects; 6 | 7 | import static io.searchbox.core.search.aggregation.AggregationField.VALUE; 8 | 9 | /** 10 | * @author cfstout 11 | */ 12 | public abstract class SingleValueAggregation extends MetricAggregation { 13 | 14 | private Double value; 15 | 16 | protected SingleValueAggregation(String name, JsonObject singleValueAggregation) { 17 | super(name, singleValueAggregation); 18 | if(singleValueAggregation.has(String.valueOf(VALUE)) && !singleValueAggregation.get(String.valueOf(VALUE)).isJsonNull()) { 19 | value = singleValueAggregation.get(String.valueOf(VALUE)).getAsDouble(); 20 | } 21 | } 22 | 23 | /** 24 | * @return value if it was found and not null, null otherwise 25 | */ 26 | protected Double getValue() { 27 | return value; 28 | } 29 | 30 | @Override 31 | public boolean equals(Object obj) { 32 | if (obj == null) { 33 | return false; 34 | } 35 | if (obj == this) { 36 | return true; 37 | } 38 | if (obj.getClass() != getClass()) { 39 | return false; 40 | } 41 | 42 | SingleValueAggregation rhs = (SingleValueAggregation) obj; 43 | return super.equals(obj) && Objects.equals(value, rhs.value); 44 | } 45 | 46 | @Override 47 | public int hashCode() { 48 | return Objects.hash(super.hashCode(), value); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/core/search/aggregation/SumAggregation.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.core.search.aggregation; 2 | 3 | import com.google.gson.JsonObject; 4 | 5 | import java.util.Objects; 6 | 7 | /** 8 | * @author cfstout 9 | */ 10 | public class SumAggregation extends SingleValueAggregation { 11 | 12 | public static final String TYPE = "sum"; 13 | 14 | public SumAggregation(String name, JsonObject sumAggregation) { 15 | super(name, sumAggregation); 16 | } 17 | 18 | public Double getSum() { 19 | return getValue(); 20 | } 21 | 22 | @Override 23 | public int hashCode() { 24 | return Objects.hash(super.hashCode(), TYPE); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/core/search/aggregation/TopHitsAggregation.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.core.search.aggregation; 2 | 3 | import java.util.List; 4 | 5 | import com.google.gson.Gson; 6 | import com.google.gson.JsonObject; 7 | 8 | import io.searchbox.core.SearchResult; 9 | 10 | public class TopHitsAggregation extends SearchResult { 11 | 12 | protected String name; 13 | protected JsonObject jsonRoot; 14 | public static final String TYPE = "top_hits"; 15 | 16 | public TopHitsAggregation(String name, JsonObject topHitAggregation) { 17 | this(name, topHitAggregation, null); 18 | } 19 | 20 | public TopHitsAggregation(String name, JsonObject topHitAggregation, Gson gson) { 21 | super(gson == null ? new Gson() : gson); 22 | this.name = name; 23 | 24 | this.setSucceeded(true); 25 | this.setJsonObject(topHitAggregation); 26 | this.setPathToResult("hits/hits/_source"); 27 | } 28 | 29 | public String getName() { 30 | return name; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/core/search/aggregation/ValueCountAggregation.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.core.search.aggregation; 2 | 3 | import com.google.gson.JsonObject; 4 | 5 | import java.util.Objects; 6 | 7 | import static io.searchbox.core.search.aggregation.AggregationField.VALUE; 8 | 9 | /** 10 | * @author cfstout 11 | */ 12 | public class ValueCountAggregation extends MetricAggregation { 13 | 14 | public static final String TYPE = "value_count"; 15 | 16 | private Long valueCount; 17 | 18 | public ValueCountAggregation(String name, JsonObject valueCountAggregation) { 19 | super(name, valueCountAggregation); 20 | valueCount = valueCountAggregation.get(String.valueOf(VALUE)).getAsLong(); 21 | } 22 | 23 | public Long getValueCount() { 24 | return valueCount; 25 | } 26 | 27 | @Override 28 | public boolean equals(Object obj) { 29 | if (obj == null) { 30 | return false; 31 | } 32 | if (obj == this) { 33 | return true; 34 | } 35 | if (obj.getClass() != getClass()) { 36 | return false; 37 | } 38 | 39 | ValueCountAggregation rhs = (ValueCountAggregation) obj; 40 | return super.equals(obj) 41 | && Objects.equals(valueCount, rhs.valueCount); 42 | } 43 | 44 | @Override 45 | public int hashCode() { 46 | return Objects.hash(super.hashCode(), valueCount); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/fields/FieldCapabilities.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.fields; 2 | 3 | import io.searchbox.action.AbstractAction; 4 | import io.searchbox.action.GenericResultAbstractAction; 5 | import io.searchbox.client.config.ElasticsearchVersion; 6 | import io.searchbox.params.Parameters; 7 | 8 | import java.util.HashMap; 9 | import java.util.Map; 10 | 11 | public class FieldCapabilities extends GenericResultAbstractAction { 12 | protected FieldCapabilities(FieldCapabilities.Builder builder) { 13 | super(builder); 14 | 15 | this.indexName = builder.index; 16 | 17 | Map fieldStatsBody = new HashMap<>(); 18 | fieldStatsBody.put("fields", builder.fields); 19 | 20 | this.payload = fieldStatsBody; 21 | } 22 | 23 | @Override 24 | public String getRestMethodName() { 25 | return "POST"; 26 | } 27 | 28 | @Override 29 | protected String buildURI(ElasticsearchVersion elasticsearchVersion) { 30 | String buildURI = super.buildURI(elasticsearchVersion); 31 | if (buildURI.isEmpty()) 32 | return "_field_caps"; 33 | 34 | return buildURI + "/_field_caps"; 35 | } 36 | 37 | 38 | public static class Builder extends AbstractAction.Builder { 39 | 40 | private String index; 41 | private Object fields; 42 | 43 | public Builder(Object fields) { 44 | this.fields = fields; 45 | } 46 | 47 | public FieldCapabilities.Builder setIndex(String index) { 48 | this.index = index; 49 | return this; 50 | } 51 | 52 | public FieldCapabilities.Builder setLevel(String level) { 53 | parameters.put(Parameters.LEVEL, level); 54 | return this; 55 | } 56 | 57 | @Override 58 | public FieldCapabilities build() { 59 | return new FieldCapabilities(this); 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/indices/ClearCache.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.indices; 2 | 3 | import io.searchbox.action.AbstractMultiIndexActionBuilder; 4 | import io.searchbox.action.GenericResultAbstractAction; 5 | import io.searchbox.client.config.ElasticsearchVersion; 6 | 7 | /** 8 | * @author Dogukan Sonmez 9 | * @author cihat keser 10 | */ 11 | public class ClearCache extends GenericResultAbstractAction { 12 | 13 | protected ClearCache(Builder builder) { 14 | super(builder); 15 | } 16 | 17 | @Override 18 | protected String buildURI(ElasticsearchVersion elasticsearchVersion) { 19 | return super.buildURI(elasticsearchVersion) + "/_cache/clear"; 20 | } 21 | 22 | @Override 23 | public String getRestMethodName() { 24 | return "POST"; 25 | } 26 | 27 | public static class Builder extends AbstractMultiIndexActionBuilder { 28 | 29 | public Builder filter(boolean filter) { 30 | setParameter("filter", filter); 31 | return this; 32 | } 33 | 34 | public Builder fieldData(boolean fieldData) { 35 | setParameter("field_data", fieldData); 36 | return this; 37 | } 38 | 39 | public Builder bloom(boolean bloom) { 40 | setParameter("bloom", bloom); 41 | return this; 42 | } 43 | 44 | @Override 45 | public ClearCache build() { 46 | return new ClearCache(this); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/indices/CloseIndex.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.indices; 2 | 3 | import io.searchbox.action.GenericResultAbstractAction; 4 | import io.searchbox.client.config.ElasticsearchVersion; 5 | 6 | /** 7 | * @author cihat keser 8 | */ 9 | public class CloseIndex extends GenericResultAbstractAction { 10 | 11 | protected CloseIndex(Builder builder) { 12 | super(builder); 13 | 14 | this.indexName = builder.index; 15 | } 16 | 17 | @Override 18 | protected String buildURI(ElasticsearchVersion elasticsearchVersion) { 19 | return super.buildURI(elasticsearchVersion) + "/_close"; 20 | } 21 | 22 | @Override 23 | public String getRestMethodName() { 24 | return "POST"; 25 | } 26 | 27 | public static class Builder extends GenericResultAbstractAction.Builder { 28 | private String index; 29 | 30 | public Builder(String index) { 31 | this.index = index; 32 | } 33 | 34 | @Override 35 | public CloseIndex build() { 36 | return new CloseIndex(this); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/indices/DeleteIndex.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.indices; 2 | 3 | import io.searchbox.action.GenericResultAbstractAction; 4 | 5 | /** 6 | * @author Dogukan Sonmez 7 | * @author cihat keser 8 | */ 9 | public class DeleteIndex extends GenericResultAbstractAction { 10 | 11 | protected DeleteIndex(Builder builder) { 12 | super(builder); 13 | indexName = builder.index; 14 | typeName = builder.type; 15 | } 16 | 17 | @Override 18 | public String getRestMethodName() { 19 | return "DELETE"; 20 | } 21 | 22 | public static class Builder extends GenericResultAbstractAction.Builder { 23 | private String index; 24 | private String type; 25 | 26 | public Builder(String index) { 27 | this.index = index; 28 | } 29 | 30 | public Builder type(String type) { 31 | this.type = type; 32 | return this; 33 | } 34 | 35 | @Override 36 | public DeleteIndex build() { 37 | return new DeleteIndex(this); 38 | } 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/indices/DocumentExists.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.indices; 2 | 3 | import com.google.gson.Gson; 4 | import io.searchbox.action.AbstractDocumentTargetedAction; 5 | 6 | public class DocumentExists extends AbstractDocumentTargetedAction { 7 | 8 | DocumentExists(DocumentExists.Builder builder) { 9 | super(builder); 10 | } 11 | 12 | @Override 13 | public String getRestMethodName() { 14 | return "HEAD"; 15 | } 16 | 17 | @Override 18 | public DocumentExistsResult createNewElasticSearchResult(String responseBody, int statusCode, String reasonPhrase, Gson gson) { 19 | return createNewElasticSearchResult(new DocumentExistsResult(gson), responseBody, statusCode, reasonPhrase, gson); 20 | } 21 | 22 | public static class Builder extends AbstractDocumentTargetedAction.Builder { 23 | 24 | public Builder(String index, String type, String id) { 25 | this.index(index); 26 | this.type(type); 27 | this.id(id); 28 | } 29 | 30 | public DocumentExists build() { 31 | return new DocumentExists(this); 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/indices/DocumentExistsResult.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.indices; 2 | 3 | import com.google.gson.Gson; 4 | import io.searchbox.client.JestResult; 5 | 6 | public class DocumentExistsResult extends JestResult { 7 | 8 | DocumentExistsResult(Gson gson) { 9 | super(gson); 10 | } 11 | 12 | public boolean documentExists() { 13 | return isSucceeded(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/indices/Flush.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.indices; 2 | 3 | import io.searchbox.action.AbstractMultiIndexActionBuilder; 4 | import io.searchbox.action.GenericResultAbstractAction; 5 | import io.searchbox.client.config.ElasticsearchVersion; 6 | 7 | /** 8 | * @author Dogukan Sonmez 9 | * @author cihat keser 10 | */ 11 | public class Flush extends GenericResultAbstractAction { 12 | 13 | protected Flush(Builder builder) { 14 | super(builder); 15 | } 16 | 17 | @Override 18 | protected String buildURI(ElasticsearchVersion elasticsearchVersion) { 19 | return super.buildURI(elasticsearchVersion) + "/_flush"; 20 | } 21 | 22 | @Override 23 | public String getRestMethodName() { 24 | return "POST"; 25 | } 26 | 27 | public static class Builder extends AbstractMultiIndexActionBuilder { 28 | public Builder force(boolean force) { 29 | return setParameter("force", force); 30 | } 31 | 32 | public Builder force() { 33 | return force(true); 34 | } 35 | 36 | public Builder waitIfOngoing(boolean waitIfOngoing) { 37 | return setParameter("wait_if_ongoing", waitIfOngoing); 38 | } 39 | 40 | public Builder waitIfOngoing() { 41 | return waitIfOngoing(true); 42 | } 43 | 44 | @Override 45 | public Flush build() { 46 | return new Flush(this); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/indices/IndicesExists.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.indices; 2 | 3 | import io.searchbox.action.AbstractMultiIndexActionBuilder; 4 | import io.searchbox.action.GenericResultAbstractAction; 5 | 6 | import java.util.Collection; 7 | 8 | /** 9 | * @author Dogukan Sonmez 10 | */ 11 | public class IndicesExists extends GenericResultAbstractAction { 12 | 13 | protected IndicesExists(Builder builder) { 14 | super(builder); 15 | } 16 | 17 | @Override 18 | public String getRestMethodName() { 19 | return "HEAD"; 20 | } 21 | 22 | public static class Builder extends AbstractMultiIndexActionBuilder { 23 | 24 | public Builder(String index){ 25 | addIndex(index); 26 | } 27 | 28 | public Builder(Collection indices){ 29 | addIndices(indices); 30 | } 31 | 32 | @Override 33 | public IndicesExists build() { 34 | return new IndicesExists(this); 35 | } 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/indices/OpenIndex.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.indices; 2 | 3 | import io.searchbox.action.GenericResultAbstractAction; 4 | import io.searchbox.client.config.ElasticsearchVersion; 5 | 6 | /** 7 | * @author cihat keser 8 | */ 9 | public class OpenIndex extends GenericResultAbstractAction { 10 | 11 | protected OpenIndex(Builder builder) { 12 | super(builder); 13 | this.indexName = builder.index; 14 | } 15 | 16 | @Override 17 | protected String buildURI(ElasticsearchVersion elasticsearchVersion) { 18 | return super.buildURI(elasticsearchVersion) + "/_open"; 19 | } 20 | 21 | @Override 22 | public String getRestMethodName() { 23 | return "POST"; 24 | } 25 | 26 | public static class Builder extends GenericResultAbstractAction.Builder { 27 | private String index; 28 | 29 | public Builder(String index) { 30 | this.index = index; 31 | } 32 | 33 | @Override 34 | public OpenIndex build() { 35 | return new OpenIndex(this); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/indices/Refresh.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.indices; 2 | 3 | import io.searchbox.action.AbstractMultiIndexActionBuilder; 4 | import io.searchbox.action.GenericResultAbstractAction; 5 | import io.searchbox.client.config.ElasticsearchVersion; 6 | 7 | /** 8 | * @author Dogukan Sonmez 9 | * @author cihat keser 10 | */ 11 | public class Refresh extends GenericResultAbstractAction { 12 | 13 | protected Refresh(Builder builder) { 14 | super(builder); 15 | } 16 | 17 | @Override 18 | public String getRestMethodName() { 19 | return "POST"; 20 | } 21 | 22 | @Override 23 | protected String buildURI(ElasticsearchVersion elasticsearchVersion) { 24 | return super.buildURI(elasticsearchVersion) + "/_refresh"; 25 | } 26 | 27 | public static class Builder extends AbstractMultiIndexActionBuilder { 28 | 29 | @Override 30 | public Refresh build() { 31 | return new Refresh(this); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/indices/Segments.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.indices; 2 | 3 | /** 4 | * @author Dogukan Sonmez 5 | */ 6 | 7 | 8 | public class Segments { 9 | } 10 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/indices/Snapshot.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.indices; 2 | 3 | /** 4 | * @author Dogukan Sonmez 5 | */ 6 | 7 | 8 | public class Snapshot { 9 | } 10 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/indices/Templates.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.indices; 2 | 3 | /** 4 | * @author Dogukan Sonmez 5 | */ 6 | 7 | 8 | public class Templates { 9 | } 10 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/indices/aliases/AddAliasMapping.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.indices.aliases; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * @author cihat keser 7 | */ 8 | public class AddAliasMapping extends AliasMapping { 9 | 10 | protected AddAliasMapping() { 11 | } 12 | 13 | protected AddAliasMapping(Builder builder) { 14 | this.indices.addAll(builder.indices); 15 | this.alias = builder.alias; 16 | this.filter = builder.filter; 17 | this.searchRouting.addAll(builder.searchRouting); 18 | this.indexRouting.addAll(builder.indexRouting); 19 | } 20 | 21 | @Override 22 | public String getType() { 23 | return "add"; 24 | } 25 | 26 | public static class Builder extends AbstractAliasMappingBuilder { 27 | 28 | public Builder(List indices, String alias) { 29 | super(indices, alias); 30 | } 31 | 32 | public Builder(String index, String alias) { 33 | super(index, alias); 34 | } 35 | 36 | @Override 37 | public AddAliasMapping build() { 38 | return new AddAliasMapping(this); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/indices/aliases/AliasExists.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.indices.aliases; 2 | 3 | import io.searchbox.action.AbstractMultiIndexActionBuilder; 4 | import io.searchbox.action.GenericResultAbstractAction; 5 | import io.searchbox.client.config.ElasticsearchVersion; 6 | 7 | public class AliasExists extends GenericResultAbstractAction { 8 | private String alias; 9 | 10 | protected AliasExists(Builder builder, String alias) { 11 | super(builder); 12 | this.alias = alias; 13 | } 14 | 15 | @Override 16 | public String getRestMethodName() { 17 | return "HEAD"; 18 | } 19 | 20 | @Override 21 | protected String buildURI(ElasticsearchVersion elasticsearchVersion) { 22 | return super.buildURI(elasticsearchVersion) + "/_alias/" + alias; 23 | } 24 | 25 | public static class Builder extends AbstractMultiIndexActionBuilder { 26 | protected String alias = "*"; 27 | 28 | public Builder alias(String alias) { 29 | this.alias = alias; 30 | return this; 31 | } 32 | 33 | @Override 34 | public AliasExists build() { 35 | return new AliasExists(this, alias); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/indices/aliases/AliasMapping.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.indices.aliases; 2 | 3 | import com.google.common.base.Joiner; 4 | 5 | import java.util.*; 6 | 7 | /** 8 | * @author cihat keser 9 | */ 10 | public abstract class AliasMapping { 11 | 12 | protected List indices = new LinkedList(); 13 | protected String alias; 14 | protected Map filter; 15 | protected List searchRouting = new LinkedList(); 16 | protected List indexRouting = new LinkedList(); 17 | 18 | public abstract String getType(); 19 | 20 | public List> getData() { 21 | List> retList = new LinkedList>(); 22 | 23 | for (String index : indices) { 24 | Map paramsMap = new LinkedHashMap(); 25 | paramsMap.put("index", index); 26 | paramsMap.put("alias", alias); 27 | 28 | if (filter != null) { 29 | paramsMap.put("filter", filter); 30 | } 31 | 32 | if (searchRouting.size() > 0) { 33 | paramsMap.put("search_routing", Joiner.on(',').join(searchRouting)); 34 | } 35 | 36 | if (indexRouting.size() > 0) { 37 | paramsMap.put("index_routing", Joiner.on(',').join(indexRouting)); 38 | } 39 | 40 | Map actionMap = new LinkedHashMap(); 41 | actionMap.put(getType(), paramsMap); 42 | retList.add(actionMap); 43 | } 44 | 45 | return retList; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/indices/aliases/RemoveAliasMapping.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.indices.aliases; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * @author cihat keser 7 | */ 8 | public class RemoveAliasMapping extends AliasMapping { 9 | 10 | protected RemoveAliasMapping() { 11 | } 12 | 13 | protected RemoveAliasMapping(Builder builder) { 14 | this.indices.addAll(builder.indices); 15 | this.alias = builder.alias; 16 | this.filter = builder.filter; 17 | this.searchRouting.addAll(builder.searchRouting); 18 | this.indexRouting.addAll(builder.indexRouting); 19 | } 20 | 21 | @Override 22 | public String getType() { 23 | return "remove"; 24 | } 25 | 26 | public static class Builder extends AbstractAliasMappingBuilder { 27 | 28 | public Builder(List indices, String alias) { 29 | super(indices, alias); 30 | } 31 | 32 | public Builder(String index, String alias) { 33 | super(index, alias); 34 | } 35 | 36 | @Override 37 | public RemoveAliasMapping build() { 38 | return new RemoveAliasMapping(this); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/indices/mapping/DeleteMapping.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.indices.mapping; 2 | 3 | 4 | import io.searchbox.action.GenericResultAbstractAction; 5 | import io.searchbox.client.config.ElasticsearchVersion; 6 | 7 | /** 8 | * @author Dogukan Sonmez 9 | * @author François Thareau 10 | */ 11 | public class DeleteMapping extends GenericResultAbstractAction { 12 | 13 | protected DeleteMapping(Builder builder) { 14 | super(builder); 15 | 16 | this.indexName = builder.index; 17 | this.typeName = builder.type; 18 | } 19 | 20 | @Override 21 | protected String buildURI(ElasticsearchVersion elasticsearchVersion) { 22 | return super.buildURI(elasticsearchVersion) + "/_mapping"; 23 | } 24 | 25 | @Override 26 | public String getRestMethodName() { 27 | return "DELETE"; 28 | } 29 | 30 | public static class Builder extends GenericResultAbstractAction.Builder { 31 | private String index; 32 | private String type; 33 | 34 | public Builder(String index, String type) { 35 | this.index = index; 36 | this.type = type; 37 | } 38 | 39 | @Override 40 | public DeleteMapping build() { 41 | return new DeleteMapping(this); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/indices/mapping/GetMapping.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.indices.mapping; 2 | 3 | import io.searchbox.action.AbstractMultiTypeActionBuilder; 4 | import io.searchbox.action.GenericResultAbstractAction; 5 | import io.searchbox.client.config.ElasticsearchVersion; 6 | 7 | /** 8 | * @author ferhat 9 | * @author cihat keser 10 | */ 11 | public class GetMapping extends GenericResultAbstractAction { 12 | 13 | protected GetMapping(Builder builder) { 14 | super(builder); 15 | } 16 | 17 | @Override 18 | public String getRestMethodName() { 19 | return "GET"; 20 | } 21 | 22 | @Override 23 | protected String buildURI(ElasticsearchVersion elasticsearchVersion) { 24 | return super.buildURI(elasticsearchVersion) + "/_mapping"; 25 | } 26 | 27 | public static class Builder extends AbstractMultiTypeActionBuilder { 28 | 29 | @Override 30 | public GetMapping build() { 31 | return new GetMapping(this); 32 | } 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/indices/mapping/PutMapping.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.indices.mapping; 2 | 3 | import io.searchbox.action.GenericResultAbstractAction; 4 | import io.searchbox.client.config.ElasticsearchVersion; 5 | 6 | /** 7 | * @author ferhat 8 | * @author cihat keser 9 | */ 10 | public class PutMapping extends GenericResultAbstractAction { 11 | 12 | protected PutMapping(Builder builder) { 13 | super(builder); 14 | 15 | this.indexName = builder.index; 16 | this.typeName = builder.type; 17 | this.payload = builder.source; 18 | } 19 | 20 | @Override 21 | protected String buildURI(ElasticsearchVersion elasticsearchVersion) { 22 | return super.buildURI(elasticsearchVersion) + "/_mapping"; 23 | } 24 | 25 | @Override 26 | public String getRestMethodName() { 27 | return "PUT"; 28 | } 29 | 30 | public static class Builder extends GenericResultAbstractAction.Builder { 31 | private String index; 32 | private String type; 33 | private Object source; 34 | 35 | public Builder(String index, String type, Object source) { 36 | this.index = index; 37 | this.type = type; 38 | this.source = source; 39 | } 40 | 41 | @Override 42 | public PutMapping build() { 43 | return new PutMapping(this); 44 | } 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/indices/script/DeleteStoredScript.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.indices.script; 2 | 3 | public class DeleteStoredScript extends AbstractStoredScript { 4 | 5 | protected DeleteStoredScript(Builder builder) { 6 | super(builder); 7 | } 8 | 9 | @Override 10 | public String getRestMethodName() { 11 | return "DELETE"; 12 | } 13 | 14 | public static class Builder extends AbstractStoredScript.Builder { 15 | 16 | public Builder(String scriptName) { 17 | super(scriptName); 18 | } 19 | 20 | @Override 21 | public DeleteStoredScript build() { 22 | return new DeleteStoredScript(this); 23 | } 24 | 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/indices/script/GetStoredScript.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.indices.script; 2 | 3 | /** 4 | * @author cihat keser 5 | */ 6 | public class GetStoredScript extends AbstractStoredScript { 7 | protected GetStoredScript(Builder builder) { 8 | super(builder); 9 | } 10 | 11 | @Override 12 | public String getRestMethodName() { 13 | return "GET"; 14 | } 15 | 16 | public static class Builder extends AbstractStoredScript.Builder { 17 | 18 | public Builder(String scriptName) { 19 | super(scriptName); 20 | } 21 | 22 | @Override 23 | public GetStoredScript build() { 24 | return new GetStoredScript(this); 25 | } 26 | 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/indices/script/ScriptLanguage.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.indices.script; 2 | 3 | /** 4 | * As described in Elasticsearch Reference 5 | * 6 | * https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting.html 7 | * 8 | */ 9 | public enum ScriptLanguage { 10 | GROOVY("groovy"), 11 | EXPRESSION("expression"), 12 | MUSTACHE("mustache"), 13 | JAVASCRIPT("javascript"), 14 | PAINLESS("painless"), 15 | PYTHON("python"); 16 | 17 | public final String pathParameterName; 18 | 19 | ScriptLanguage(String pathParameterName) { 20 | this.pathParameterName = pathParameterName; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/indices/settings/GetSettings.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.indices.settings; 2 | 3 | import io.searchbox.action.AbstractMultiIndexActionBuilder; 4 | 5 | /** 6 | * The get settings API allows to retrieve settings of index/indices. 7 | * 8 | * @author Dogukan Sonmez 9 | * @author cihat keser 10 | */ 11 | public class GetSettings extends IndicesSettingsAbstractAction { 12 | 13 | protected GetSettings(Builder builder) { 14 | super(builder); 15 | } 16 | 17 | @Override 18 | public String getRestMethodName() { 19 | return "GET"; 20 | } 21 | 22 | public static class Builder extends AbstractMultiIndexActionBuilder { 23 | 24 | @Override 25 | public GetSettings build() { 26 | return new GetSettings(this); 27 | } 28 | 29 | /** 30 | * Prefix Query Option allows to include only settings (whose keys) matches the specified prefix. 31 | */ 32 | public Builder prefixQuery(String prefixQuery) { 33 | return setParameter("prefix", prefixQuery); 34 | } 35 | 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/indices/settings/IndicesSettingsAbstractAction.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.indices.settings; 2 | 3 | import io.searchbox.action.GenericResultAbstractAction; 4 | import io.searchbox.client.config.ElasticsearchVersion; 5 | 6 | /** 7 | * @author cihat keser 8 | */ 9 | public abstract class IndicesSettingsAbstractAction extends GenericResultAbstractAction { 10 | 11 | protected IndicesSettingsAbstractAction(Builder builder) { 12 | super(builder); 13 | } 14 | 15 | @Override 16 | protected String buildURI(ElasticsearchVersion elasticsearchVersion) { 17 | return super.buildURI(elasticsearchVersion) + "/_settings"; 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/indices/settings/UpdateSettings.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.indices.settings; 2 | 3 | import io.searchbox.action.AbstractMultiIndexActionBuilder; 4 | 5 | /** 6 | * Change specific index level settings in real time. 7 | * 8 | * @author Dogukan Sonmez 9 | * @author cihat keser 10 | */ 11 | public class UpdateSettings extends IndicesSettingsAbstractAction { 12 | 13 | protected UpdateSettings(Builder builder) { 14 | super(builder); 15 | this.payload = builder.source; 16 | } 17 | 18 | @Override 19 | public String getRestMethodName() { 20 | return "PUT"; 21 | } 22 | 23 | public static class Builder extends AbstractMultiIndexActionBuilder { 24 | private final Object source; 25 | 26 | /** 27 | * Please see the related page on Elasticsearch guide 28 | * for the list of settings that can be changed using this action/API. 29 | * 30 | * @param source body of request that includes updated settings 31 | */ 32 | public Builder(Object source) { 33 | this.source = source; 34 | } 35 | 36 | @Override 37 | public UpdateSettings build() { 38 | return new UpdateSettings(this); 39 | } 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/indices/template/DeleteTemplate.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.indices.template; 2 | 3 | /** 4 | * @author asierdelpozo 5 | * @author cihat keser 6 | */ 7 | public class DeleteTemplate extends TemplateAction { 8 | 9 | protected DeleteTemplate(Builder builder) { 10 | super(builder); 11 | } 12 | 13 | @Override 14 | public String getRestMethodName() { 15 | return "DELETE"; 16 | } 17 | 18 | public static class Builder extends TemplateAction.Builder { 19 | 20 | public Builder(String template) { 21 | super(template); 22 | } 23 | 24 | @Override 25 | public DeleteTemplate build() { 26 | return new DeleteTemplate(this); 27 | } 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/indices/template/GetTemplate.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.indices.template; 2 | 3 | /** 4 | * @author asierdelpozo 5 | * @author cihat keser 6 | */ 7 | public class GetTemplate extends TemplateAction { 8 | 9 | protected GetTemplate(Builder builder) { 10 | super(builder); 11 | } 12 | 13 | @Override 14 | public String getRestMethodName() { 15 | return "GET"; 16 | } 17 | 18 | public static class Builder extends TemplateAction.Builder { 19 | 20 | public Builder(String template) { 21 | super(template); 22 | } 23 | 24 | @Override 25 | public GetTemplate build() { 26 | return new GetTemplate(this); 27 | } 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/indices/template/PutTemplate.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.indices.template; 2 | 3 | /** 4 | * @author asierdelpozo 5 | * @author cihat keser 6 | */ 7 | public class PutTemplate extends TemplateAction { 8 | 9 | protected PutTemplate(Builder builder) { 10 | super(builder); 11 | 12 | this.payload = builder.source; 13 | } 14 | 15 | @Override 16 | public String getRestMethodName() { 17 | return "PUT"; 18 | } 19 | 20 | public static class Builder extends TemplateAction.Builder { 21 | 22 | private Object source; 23 | 24 | public Builder(String template, Object source) { 25 | super(template); 26 | this.source = source; 27 | } 28 | 29 | @Override 30 | public PutTemplate build() { 31 | return new PutTemplate(this); 32 | } 33 | } 34 | 35 | } 36 | 37 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/indices/template/TemplateAction.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.indices.template; 2 | 3 | import io.searchbox.action.GenericResultAbstractAction; 4 | import io.searchbox.client.config.ElasticsearchVersion; 5 | 6 | /** 7 | * @author cihat keser 8 | */ 9 | public abstract class TemplateAction extends GenericResultAbstractAction { 10 | 11 | protected String templateName; 12 | 13 | protected TemplateAction(Builder builder) { 14 | super(builder); 15 | templateName = builder.template; 16 | } 17 | 18 | @Override 19 | protected String buildURI(ElasticsearchVersion elasticsearchVersion) { 20 | return "_template/" + templateName; 21 | } 22 | 23 | protected abstract static class Builder extends GenericResultAbstractAction.Builder { 24 | protected String template; 25 | 26 | public Builder(String template) { 27 | this.template = template; 28 | } 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/indices/type/TypeExist.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.indices.type; 2 | 3 | import io.searchbox.action.AbstractMultiTypeActionBuilder; 4 | import io.searchbox.action.GenericResultAbstractAction; 5 | import io.searchbox.client.config.ElasticsearchVersion; 6 | 7 | /** 8 | * @author happyprg(hongsgo @ gmail.com) 9 | */ 10 | public class TypeExist extends GenericResultAbstractAction { 11 | 12 | TypeExist(Builder builder) { 13 | 14 | super(builder); 15 | } 16 | 17 | @Override 18 | protected String getURLCommandExtension(ElasticsearchVersion elasticsearchVersion) { 19 | return "_mapping"; 20 | } 21 | 22 | @Override 23 | public String getRestMethodName() { 24 | return "HEAD"; 25 | } 26 | 27 | public static class Builder extends AbstractMultiTypeActionBuilder { 28 | 29 | public Builder(String index) { 30 | this.addIndex(index); 31 | } 32 | 33 | @Override 34 | public TypeExist build() { 35 | return new TypeExist(this); 36 | } 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/params/SearchType.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.params; 2 | 3 | /** 4 | * @author ferhat 5 | */ 6 | public enum SearchType { 7 | 8 | DFS_QUERY_THEN_FETCH("dfs_query_then_fetch"), 9 | QUERY_THEN_FETCH("query_then_fetch"), 10 | COUNT("count"), 11 | SCAN("scan"); 12 | 13 | private String value; 14 | 15 | SearchType(String value) { 16 | this.value = value; 17 | } 18 | 19 | public String toString() { 20 | return this.value; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/snapshot/AbstractSnapshotRepositoryAction.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.snapshot; 2 | 3 | import io.searchbox.action.GenericResultAbstractAction; 4 | import io.searchbox.client.config.ElasticsearchVersion; 5 | 6 | /** 7 | * @author ckeser 8 | */ 9 | public abstract class AbstractSnapshotRepositoryAction extends GenericResultAbstractAction { 10 | 11 | private String repositories; 12 | 13 | protected AbstractSnapshotRepositoryAction(RepositoryBuilder builder) { 14 | super(builder); 15 | 16 | this.repositories = builder.getRepositories(); 17 | } 18 | 19 | @Override 20 | protected String buildURI(ElasticsearchVersion elasticsearchVersion) { 21 | return super.buildURI(elasticsearchVersion) + "/_snapshot/" + repositories; 22 | } 23 | 24 | public abstract static class RepositoryBuilder extends Builder { 25 | protected abstract String getRepositories(); 26 | } 27 | 28 | public abstract static class SingleRepositoryBuilder extends RepositoryBuilder { 29 | private String repository; 30 | 31 | public SingleRepositoryBuilder(String repository) { 32 | this.repository = repository; 33 | } 34 | 35 | protected String getRepositories() { 36 | return repository; 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/snapshot/CreateSnapshot.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.snapshot; 2 | 3 | /** 4 | * @author happyprg(hongsgo@gmail.com) 5 | */ 6 | public class CreateSnapshot extends AbstractSnapshotAction { 7 | 8 | protected CreateSnapshot(Builder builder) { 9 | super(builder); 10 | this.payload = builder.settings; 11 | } 12 | 13 | @Override 14 | public String getRestMethodName() { 15 | return "PUT"; 16 | } 17 | 18 | public static class Builder extends AbstractSnapshotAction.SingleSnapshotBuilder { 19 | private Object settings; 20 | 21 | public Builder(String repository, String snapshot) { 22 | super(repository, snapshot); 23 | } 24 | 25 | public Builder settings(Object settings) { 26 | this.settings = settings; 27 | return this; 28 | } 29 | 30 | public Builder waitForCompletion(boolean waitForCompletion) { 31 | return setParameter("wait_for_completion", waitForCompletion); 32 | } 33 | 34 | @Override 35 | public CreateSnapshot build() { 36 | return new CreateSnapshot(this); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/snapshot/CreateSnapshotRepository.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.snapshot; 2 | 3 | /** 4 | * @author happyprg(hongsgo@gmail.com) 5 | */ 6 | public class CreateSnapshotRepository extends AbstractSnapshotRepositoryAction { 7 | 8 | protected CreateSnapshotRepository(Builder builder) { 9 | super(builder); 10 | 11 | this.payload = builder.settings; 12 | } 13 | 14 | @Override 15 | public String getRestMethodName() { 16 | return "PUT"; 17 | } 18 | 19 | public static class Builder extends AbstractSnapshotRepositoryAction.SingleRepositoryBuilder { 20 | private Object settings; 21 | 22 | public Builder(String repository) { 23 | super(repository); 24 | } 25 | 26 | public Builder settings(Object settings) { 27 | this.settings = settings; 28 | return this; 29 | } 30 | 31 | public Builder verify(boolean verify) { 32 | return setParameter("verify", verify); 33 | } 34 | 35 | @Override 36 | public CreateSnapshotRepository build() { 37 | return new CreateSnapshotRepository(this); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/snapshot/DeleteSnapshot.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.snapshot; 2 | 3 | /** 4 | * @author happyprg(hongsgo@gmail.com) 5 | */ 6 | public class DeleteSnapshot extends AbstractSnapshotAction { 7 | 8 | protected DeleteSnapshot(Builder builder) { 9 | super(builder); 10 | } 11 | 12 | @Override 13 | public String getRestMethodName() { 14 | return "DELETE"; 15 | } 16 | 17 | public static class Builder extends AbstractSnapshotAction.SingleSnapshotBuilder { 18 | public Builder(String repository, String snapshot) { 19 | super(repository, snapshot); 20 | } 21 | 22 | @Override 23 | public DeleteSnapshot build() { 24 | return new DeleteSnapshot(this); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/snapshot/DeleteSnapshotRepository.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.snapshot; 2 | 3 | /** 4 | * @author happyprg(hongsgo@gmail.com) 5 | */ 6 | public class DeleteSnapshotRepository extends AbstractSnapshotRepositoryAction { 7 | 8 | protected DeleteSnapshotRepository(Builder builder) { 9 | super(builder); 10 | } 11 | 12 | @Override 13 | public String getRestMethodName() { 14 | return "DELETE"; 15 | } 16 | 17 | public static class Builder extends AbstractSnapshotRepositoryAction.SingleRepositoryBuilder { 18 | public Builder(String repository) { 19 | super(repository); 20 | } 21 | 22 | @Override 23 | public DeleteSnapshotRepository build() { 24 | return new DeleteSnapshotRepository(this); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/snapshot/GetSnapshot.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.snapshot; 2 | 3 | /** 4 | * @author happyprg(hongsgo@gmail.com) 5 | */ 6 | public class GetSnapshot extends AbstractSnapshotAction { 7 | 8 | protected GetSnapshot(Builder builder) { 9 | super(builder); 10 | } 11 | 12 | @Override 13 | public String getRestMethodName() { 14 | return "GET"; 15 | } 16 | 17 | public static class Builder extends AbstractSnapshotAction.MultipleSnapshotBuilder { 18 | 19 | public Builder(String repository) { 20 | super(repository); 21 | } 22 | 23 | @Override 24 | public GetSnapshot build() { 25 | return new GetSnapshot(this); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/snapshot/GetSnapshotRepository.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.snapshot; 2 | 3 | import com.google.common.base.Joiner; 4 | 5 | import java.util.Collection; 6 | import java.util.LinkedHashSet; 7 | import java.util.Set; 8 | 9 | /** 10 | * @author happyprg(hongsgo@gmail.com) 11 | */ 12 | public class GetSnapshotRepository extends AbstractSnapshotRepositoryAction { 13 | 14 | protected GetSnapshotRepository(Builder builder) { 15 | super(builder); 16 | } 17 | 18 | @Override 19 | public String getRestMethodName() { 20 | return "GET"; 21 | } 22 | 23 | public static class Builder extends AbstractSnapshotRepositoryAction.RepositoryBuilder { 24 | private Set repositories = new LinkedHashSet(); 25 | 26 | public Builder() { 27 | } 28 | 29 | public Builder(String repository) { 30 | this.repositories.add(repository); 31 | } 32 | 33 | public Builder(Collection repositories) { 34 | this.repositories.addAll(repositories); 35 | } 36 | 37 | public Builder addRepository(Collection repositories) { 38 | this.repositories.addAll(repositories); 39 | return this; 40 | } 41 | 42 | @Override 43 | public GetSnapshotRepository build() { 44 | return new GetSnapshotRepository(this); 45 | } 46 | 47 | @Override 48 | protected String getRepositories() { 49 | if (repositories.isEmpty()) { 50 | return "_all"; 51 | } else { 52 | return Joiner.on(',').join(repositories); 53 | } 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/snapshot/RestoreSnapshot.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.snapshot; 2 | 3 | import io.searchbox.client.config.ElasticsearchVersion; 4 | 5 | /** 6 | * @author happyprg(hongsgo@gmail.com) 7 | */ 8 | public class RestoreSnapshot extends AbstractSnapshotAction { 9 | 10 | protected RestoreSnapshot(Builder builder) { 11 | super(builder); 12 | this.payload = builder.settings; 13 | } 14 | 15 | @Override 16 | protected String buildURI(ElasticsearchVersion elasticsearchVersion) { 17 | return super.buildURI(elasticsearchVersion) + "/_restore"; 18 | } 19 | 20 | @Override 21 | public String getRestMethodName() { 22 | return "POST"; 23 | } 24 | 25 | public static class Builder extends AbstractSnapshotAction.SingleSnapshotBuilder { 26 | private Object settings; 27 | 28 | public Builder(String repository, String snapshot) { 29 | super(repository, snapshot); 30 | } 31 | 32 | public Builder settings(Object settings) { 33 | this.settings = settings; 34 | return this; 35 | } 36 | 37 | @Override 38 | public RestoreSnapshot build() { 39 | return new RestoreSnapshot(this); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/snapshot/SnapshotStatus.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.snapshot; 2 | 3 | import io.searchbox.client.config.ElasticsearchVersion; 4 | 5 | /** 6 | * @author happyprg(hongsgo@gmail.com) 7 | */ 8 | public class SnapshotStatus extends AbstractSnapshotAction { 9 | 10 | protected SnapshotStatus(Builder builder) { 11 | super(builder); 12 | } 13 | 14 | @Override 15 | protected String buildURI(ElasticsearchVersion elasticsearchVersion) { 16 | return super.buildURI(elasticsearchVersion) + "/_status"; 17 | } 18 | 19 | @Override 20 | public String getRestMethodName() { 21 | return "GET"; 22 | } 23 | 24 | public static class Builder extends AbstractSnapshotAction.MultipleSnapshotBuilder { 25 | public Builder(String repository) { 26 | super(repository); 27 | } 28 | 29 | @Override 30 | public SnapshotStatus build() { 31 | return new SnapshotStatus(this); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /jest-common/src/main/java/io/searchbox/strings/StringUtils.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.strings; 2 | 3 | public class StringUtils { 4 | private StringUtils() {} 5 | 6 | public static boolean isBlank(final CharSequence cs) { 7 | int strLen; 8 | if (cs == null || (strLen = cs.length()) == 0) { 9 | return true; 10 | } 11 | for (int i = 0; i < strLen; i++) { 12 | if (Character.isWhitespace(cs.charAt(i)) == false) { 13 | return false; 14 | } 15 | } 16 | return true; 17 | } 18 | 19 | public static boolean isNotBlank(final CharSequence cs) { 20 | return !isBlank(cs); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /jest-common/src/test/java/io/searchbox/client/config/ClientConfigTest.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.client.config; 2 | 3 | import org.junit.Test; 4 | 5 | import java.util.concurrent.TimeUnit; 6 | 7 | import static org.junit.Assert.assertEquals; 8 | import static org.junit.Assert.assertTrue; 9 | 10 | /** 11 | * @author Min Cha 12 | */ 13 | public class ClientConfigTest { 14 | 15 | @Test 16 | public void testTimeoutSettings() { 17 | ClientConfig config = new ClientConfig.Builder("someUri").connTimeout(1500).readTimeout(2000).build(); 18 | 19 | assertEquals(1500, config.getConnTimeout()); 20 | assertEquals(2000, config.getReadTimeout()); 21 | } 22 | 23 | @Test 24 | public void testTimeoutSettingsAsDefault() { 25 | ClientConfig config = new ClientConfig.Builder("someUri").multiThreaded(true).build(); 26 | 27 | assertTrue(config.getConnTimeout() > 0); 28 | assertTrue(config.getReadTimeout() > 0); 29 | } 30 | 31 | @Test 32 | public void testDefaultMaxIdleConnectionTime() { 33 | ClientConfig config = new ClientConfig.Builder("someUri").multiThreaded(true).build(); 34 | 35 | assertEquals(-1L, config.getMaxConnectionIdleTime()); 36 | assertEquals(TimeUnit.SECONDS, config.getMaxConnectionIdleTimeDurationTimeUnit()); 37 | } 38 | 39 | @Test 40 | public void testCustomMaxIdleConnectionTime() { 41 | ClientConfig config = new ClientConfig.Builder("someUri").multiThreaded(true) 42 | .maxConnectionIdleTime(30L, TimeUnit.MINUTES) 43 | .build(); 44 | assertEquals(30L, config.getMaxConnectionIdleTime()); 45 | assertEquals(TimeUnit.MINUTES, config.getMaxConnectionIdleTimeDurationTimeUnit()); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /jest-common/src/test/java/io/searchbox/cluster/NodesHotThreadsTest.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.cluster; 2 | 3 | import io.searchbox.client.config.ElasticsearchVersion; 4 | import org.junit.Test; 5 | 6 | import static org.junit.Assert.assertEquals; 7 | 8 | /** 9 | * @author cihat keser 10 | */ 11 | public class NodesHotThreadsTest { 12 | 13 | @Test 14 | public void testUriGenerationWithAllNodes() { 15 | NodesHotThreads action = new NodesHotThreads.Builder().build(); 16 | assertEquals("/_nodes/_all/hot_threads", action.getURI(ElasticsearchVersion.UNKNOWN)); 17 | } 18 | 19 | @Test 20 | public void testUriGenerationWithSingleNode() { 21 | NodesHotThreads action = new NodesHotThreads.Builder().addNode("Pony").build(); 22 | assertEquals("/_nodes/Pony/hot_threads", action.getURI(ElasticsearchVersion.UNKNOWN)); 23 | } 24 | 25 | @Test 26 | public void testUriGenerationWithSingleNodeAndParameter() { 27 | NodesHotThreads action = new NodesHotThreads.Builder().addNode("Pony").interval("100ms").build(); 28 | assertEquals("/_nodes/Pony/hot_threads?interval=100ms", action.getURI(ElasticsearchVersion.UNKNOWN)); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /jest-common/src/test/java/io/searchbox/cluster/NodesShutdownTest.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.cluster; 2 | 3 | import io.searchbox.client.config.ElasticsearchVersion; 4 | import org.junit.Test; 5 | 6 | import static org.junit.Assert.assertEquals; 7 | 8 | /** 9 | * @author cihat keser 10 | */ 11 | public class NodesShutdownTest { 12 | 13 | @Test 14 | public void testBuildURI() throws Exception { 15 | NodesShutdown action = new NodesShutdown.Builder().build(); 16 | assertEquals("/_nodes/_all/_shutdown", action.getURI(ElasticsearchVersion.UNKNOWN)); 17 | } 18 | 19 | @Test 20 | public void testBuildURIWithDelay() throws Exception { 21 | NodesShutdown action = new NodesShutdown.Builder().delay("5s").build(); 22 | assertEquals("/_nodes/_all/_shutdown?delay=5s", action.getURI(ElasticsearchVersion.UNKNOWN)); 23 | } 24 | 25 | @Test 26 | public void testBuildURIWithNodes() throws Exception { 27 | NodesShutdown action = new NodesShutdown.Builder().addNode("_local").build(); 28 | assertEquals("/_nodes/_local/_shutdown", action.getURI(ElasticsearchVersion.UNKNOWN)); 29 | } 30 | 31 | @Test 32 | public void testBuildURIWithNodeAttributeWildcard() throws Exception { 33 | NodesShutdown action = new NodesShutdown.Builder().addNode("ra*:2*").build(); 34 | assertEquals("/_nodes/ra*:2*/_shutdown", action.getURI(ElasticsearchVersion.UNKNOWN)); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /jest-common/src/test/java/io/searchbox/cluster/NodesStatsTest.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.cluster; 2 | 3 | import io.searchbox.client.config.ElasticsearchVersion; 4 | import org.junit.Test; 5 | 6 | import static org.junit.Assert.assertEquals; 7 | 8 | /** 9 | * @author cihat keser 10 | */ 11 | public class NodesStatsTest { 12 | 13 | @Test 14 | public void testUriGeneration() throws Exception { 15 | NodesStats action = new NodesStats.Builder() 16 | .build(); 17 | assertEquals("/_nodes/_all/stats", action.getURI(ElasticsearchVersion.UNKNOWN)); 18 | } 19 | 20 | @Test 21 | public void testUriGenerationWithSingleNode() throws Exception { 22 | NodesStats action = new NodesStats.Builder() 23 | .addNode("james") 24 | .withOs() 25 | .withJvm() 26 | .build(); 27 | assertEquals("/_nodes/james/stats/os,jvm", action.getURI(ElasticsearchVersion.UNKNOWN)); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /jest-common/src/test/java/io/searchbox/cluster/PendingClusterTasksTest.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.cluster; 2 | 3 | import io.searchbox.client.config.ElasticsearchVersion; 4 | import org.junit.Test; 5 | 6 | import static org.junit.Assert.assertEquals; 7 | 8 | public class PendingClusterTasksTest { 9 | @Test 10 | public void testUriGeneration() { 11 | PendingClusterTasks action = new PendingClusterTasks.Builder().build(); 12 | assertEquals("/_cluster/pending_tasks", action.getURI(ElasticsearchVersion.UNKNOWN)); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /jest-common/src/test/java/io/searchbox/cluster/RerouteTest.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.cluster; 2 | 3 | import com.google.gson.Gson; 4 | import io.searchbox.client.config.ElasticsearchVersion; 5 | import io.searchbox.cluster.reroute.RerouteAllocateReplica; 6 | import io.searchbox.cluster.reroute.RerouteCancel; 7 | import io.searchbox.cluster.reroute.RerouteMove; 8 | import io.searchbox.cluster.reroute.RerouteCommand; 9 | import org.json.JSONException; 10 | import org.junit.Test; 11 | import org.skyscreamer.jsonassert.JSONAssert; 12 | 13 | import java.util.LinkedList; 14 | import java.util.List; 15 | 16 | import static org.junit.Assert.assertEquals; 17 | 18 | public class RerouteTest { 19 | 20 | @Test 21 | public void reroute() throws JSONException { 22 | List moveCommands = new LinkedList(); 23 | moveCommands.add(new RerouteMove("index1", 1, "node1", "node2")); 24 | moveCommands.add(new RerouteCancel("index2", 1, "node2", true)); 25 | moveCommands.add(new RerouteAllocateReplica("index3", 1, "node3")); 26 | 27 | Reroute reroute = new Reroute.Builder(moveCommands).build(); 28 | assertEquals("/_cluster/reroute", reroute.getURI(ElasticsearchVersion.UNKNOWN)); 29 | assertEquals("POST", reroute.getRestMethodName()); 30 | 31 | String expectedData = "{ \"commands\": [" + 32 | "{ \"move\": { \"index\": \"index1\", \"shard\": 1, \"from_node\": \"node1\", \"to_node\": \"node2\" } }, " + 33 | "{ \"cancel\": { \"index\": \"index2\", \"shard\": 1, \"node\": \"node2\", \"allow_primary\": true } }," + 34 | "{ \"allocate_replica\": { \"index\": \"index3\", \"shard\": 1, \"node\": \"node3\" } }" + 35 | "] }"; 36 | JSONAssert.assertEquals(expectedData, reroute.getData(new Gson()), false); 37 | } 38 | 39 | } -------------------------------------------------------------------------------- /jest-common/src/test/java/io/searchbox/cluster/StateTest.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.cluster; 2 | 3 | import io.searchbox.client.config.ElasticsearchVersion; 4 | import org.junit.Test; 5 | 6 | import static org.junit.Assert.assertEquals; 7 | 8 | /** 9 | * @author cihat keser 10 | */ 11 | public class StateTest { 12 | 13 | @Test 14 | public void testUriGeneration() { 15 | State action = new State.Builder().build(); 16 | assertEquals("/_cluster/state", action.getURI(ElasticsearchVersion.UNKNOWN)); 17 | } 18 | 19 | @Test 20 | public void testUriGenerationWithOptionalFields() { 21 | State action = new State.Builder() 22 | .withBlocks() 23 | .withMetadata() 24 | .build(); 25 | assertEquals("/_cluster/state/blocks,metadata", action.getURI(ElasticsearchVersion.UNKNOWN)); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /jest-common/src/test/java/io/searchbox/cluster/StatsTest.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.cluster; 2 | 3 | import io.searchbox.client.config.ElasticsearchVersion; 4 | import org.junit.Test; 5 | 6 | import static org.junit.Assert.assertEquals; 7 | 8 | public class StatsTest { 9 | @Test 10 | public void testUriGeneration() { 11 | Stats action = new Stats.Builder().build(); 12 | assertEquals("/_cluster/stats/nodes/_all", action.getURI(ElasticsearchVersion.UNKNOWN)); 13 | } 14 | 15 | @Test 16 | public void testUriGenerationWithSpecificNodes() { 17 | Stats action = new Stats.Builder() 18 | .addNode("test1") 19 | .addNode("test2") 20 | .build(); 21 | assertEquals("/_cluster/stats/nodes/test1,test2", action.getURI(ElasticsearchVersion.UNKNOWN)); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /jest-common/src/test/java/io/searchbox/cluster/TasksInformationTest.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.cluster; 2 | 3 | import io.searchbox.client.config.ElasticsearchVersion; 4 | import org.junit.Test; 5 | 6 | import static org.junit.Assert.*; 7 | 8 | public class TasksInformationTest { 9 | 10 | @Test 11 | public void testUriGeneration() { 12 | TasksInformation action = new TasksInformation.Builder().build(); 13 | assertEquals("_tasks", action.getURI(ElasticsearchVersion.UNKNOWN)); 14 | } 15 | 16 | @Test 17 | public void testUriGenerationSpecificTask() { 18 | TasksInformation action = new TasksInformation.Builder().task("node_id:task_id").build(); 19 | assertEquals("_tasks/node_id:task_id", action.getURI(ElasticsearchVersion.UNKNOWN)); 20 | } 21 | } -------------------------------------------------------------------------------- /jest-common/src/test/java/io/searchbox/cluster/reroute/RerouteAllocateReplicaTest.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.cluster.reroute; 2 | 3 | import com.google.gson.Gson; 4 | import org.json.JSONException; 5 | import org.junit.Test; 6 | import org.skyscreamer.jsonassert.JSONAssert; 7 | 8 | import static org.junit.Assert.*; 9 | 10 | public class RerouteAllocateReplicaTest { 11 | 12 | @Test 13 | public void allowPrimaryTrue() throws JSONException { 14 | RerouteAllocateReplica allocateReplica = new RerouteAllocateReplica("index1", 1, "node1"); 15 | 16 | assertEquals(allocateReplica.getType(), "allocate_replica"); 17 | 18 | String actualJson = new Gson().toJson(allocateReplica.getData()); 19 | String expectedJson = "{\"index\":\"index1\", \"shard\": 1, \"node\": \"node1\", \"allow_primary\": true}"; 20 | JSONAssert.assertEquals(actualJson, expectedJson, false); 21 | } 22 | 23 | @Test 24 | public void allowPrimaryFalse() throws JSONException { 25 | RerouteAllocateReplica allocateReplica = new RerouteAllocateReplica("index1", 1, "node1"); 26 | 27 | assertEquals(allocateReplica.getType(), "allocate_replica"); 28 | 29 | String actualJson = new Gson().toJson(allocateReplica.getData()); 30 | String expectedJson = "{\"index\":\"index1\", \"shard\": 1, \"node\": \"node1\", \"allow_primary\": false}"; 31 | JSONAssert.assertEquals(actualJson, expectedJson, false); 32 | } 33 | 34 | } -------------------------------------------------------------------------------- /jest-common/src/test/java/io/searchbox/cluster/reroute/RerouteCancelTest.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.cluster.reroute; 2 | 3 | import com.google.gson.Gson; 4 | import org.json.JSONException; 5 | import org.junit.Test; 6 | import org.skyscreamer.jsonassert.JSONAssert; 7 | 8 | import static org.junit.Assert.*; 9 | 10 | public class RerouteCancelTest { 11 | 12 | @Test 13 | public void allowPrimaryTrue() throws JSONException { 14 | RerouteCancel rerouteCancel = new RerouteCancel("index1", 1, "node1", true); 15 | 16 | assertEquals(rerouteCancel.getType(), "cancel"); 17 | 18 | String actualJson = new Gson().toJson(rerouteCancel.getData()); 19 | String expectedJson = "{\"index\":\"index1\", \"shard\": 1, \"node\": \"node1\", \"allow_primary\": true}"; 20 | JSONAssert.assertEquals(actualJson, expectedJson, false); 21 | } 22 | 23 | @Test 24 | public void allowPrimaryFalse() throws JSONException { 25 | RerouteCancel rerouteCancel = new RerouteCancel("index1", 1, "node1", false); 26 | 27 | assertEquals(rerouteCancel.getType(), "cancel"); 28 | 29 | String actualJson = new Gson().toJson(rerouteCancel.getData()); 30 | String expectedJson = "{\"index\":\"index1\", \"shard\": 1, \"node\": \"node1\", \"allow_primary\": false}"; 31 | JSONAssert.assertEquals(actualJson, expectedJson, false); 32 | } 33 | 34 | } -------------------------------------------------------------------------------- /jest-common/src/test/java/io/searchbox/cluster/reroute/RerouteMoveTest.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.cluster.reroute; 2 | 3 | import com.google.gson.Gson; 4 | import org.json.JSONException; 5 | import org.junit.Test; 6 | import org.skyscreamer.jsonassert.JSONAssert; 7 | 8 | import static org.junit.Assert.*; 9 | 10 | public class RerouteMoveTest { 11 | 12 | @Test 13 | public void move() throws JSONException { 14 | RerouteMove rerouteMove = new RerouteMove("index1", 1, "node1", "node2"); 15 | 16 | assertEquals(rerouteMove.getType(), "move"); 17 | 18 | String actualJson = new Gson().toJson(rerouteMove.getData()); 19 | String expectedJson = "{\"index\":\"index1\", \"shard\": 1, \"from_node\": \"node1\", \"to_node\": \"node2\"}"; 20 | JSONAssert.assertEquals(actualJson, expectedJson, false); 21 | } 22 | 23 | } -------------------------------------------------------------------------------- /jest-common/src/test/java/io/searchbox/core/CatAliasesBuilderTest.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.core; 2 | 3 | import io.searchbox.client.config.ElasticsearchVersion; 4 | import org.junit.Test; 5 | 6 | import static org.junit.Assert.assertEquals; 7 | 8 | /** 9 | * @author Bartosz Polnik 10 | */ 11 | public class CatAliasesBuilderTest { 12 | @Test 13 | public void shouldSetApplicationJsonHeader() { 14 | Cat cat = new Cat.AliasesBuilder().build(); 15 | assertEquals("application/json", cat.getHeader("accept")); 16 | assertEquals("application/json", cat.getHeader("content-type")); 17 | } 18 | 19 | @Test 20 | public void shouldGenerateValidUriWhenIndexNotGiven() { 21 | Cat cat = new Cat.AliasesBuilder().build(); 22 | assertEquals("_cat/aliases/_all", cat.getURI(ElasticsearchVersion.UNKNOWN)); 23 | } 24 | 25 | @Test 26 | public void shouldGenerateValidUriWhenIndexGiven() { 27 | Cat cat = new Cat.AliasesBuilder().addIndex("testIndex").build(); 28 | assertEquals("_cat/aliases/testIndex", cat.getURI(ElasticsearchVersion.UNKNOWN)); 29 | } 30 | 31 | @Test 32 | public void shouldGenerateValidUriWhenParameterGiven() { 33 | Cat cat = new Cat.AliasesBuilder().setParameter("v", "true").build(); 34 | assertEquals("_cat/aliases/_all?v=true", cat.getURI(ElasticsearchVersion.UNKNOWN)); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /jest-common/src/test/java/io/searchbox/core/CatAllocationBuilderTest.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.core; 2 | 3 | import io.searchbox.client.config.ElasticsearchVersion; 4 | import org.junit.Test; 5 | 6 | import static org.junit.Assert.assertEquals; 7 | 8 | public class CatAllocationBuilderTest { 9 | @Test 10 | public void shouldSetApplicationJsonHeader() { 11 | Cat cat = new Cat.AllocationBuilder().build(); 12 | assertEquals("application/json", cat.getHeader("accept")); 13 | assertEquals("application/json", cat.getHeader("content-type")); 14 | } 15 | 16 | @Test 17 | public void shouldGenerateValidUriWhenIndexNotGiven() { 18 | Cat cat = new Cat.AllocationBuilder().build(); 19 | assertEquals("_cat/allocation", cat.getURI(ElasticsearchVersion.UNKNOWN)); 20 | } 21 | 22 | @Test 23 | public void shouldGenerateValidUriWhenSingleNodeGiven() { 24 | Cat cat = new Cat.AllocationBuilder().addNode("testNode").build(); 25 | assertEquals("_cat/allocation/testNode", cat.getURI(ElasticsearchVersion.UNKNOWN)); 26 | } 27 | 28 | @Test 29 | public void shouldGenerateValidUriWhenNodesGiven() { 30 | Cat cat = new Cat.AllocationBuilder().addNode("testNode1").addNode("testNode2").build(); 31 | assertEquals("_cat/allocation/testNode1%2CtestNode2", cat.getURI(ElasticsearchVersion.UNKNOWN)); 32 | } 33 | 34 | @Test 35 | public void shouldGenerateValidUriWhenParameterGiven() { 36 | Cat cat = new Cat.AllocationBuilder().setParameter("v", "true").build(); 37 | assertEquals("_cat/allocation?v=true", cat.getURI(ElasticsearchVersion.UNKNOWN)); 38 | } 39 | 40 | @Test 41 | public void shouldGenerateValidUriWhenHeadersParameterGiven() { 42 | Cat cat = new Cat.AllocationBuilder().setParameter("h", "shards,disk.indices,disk.used").build(); 43 | assertEquals("_cat/allocation?h=shards%2Cdisk.indices%2Cdisk.used", cat.getURI(ElasticsearchVersion.UNKNOWN)); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /jest-common/src/test/java/io/searchbox/core/CatIndicesBuilderTest.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.core; 2 | 3 | import io.searchbox.client.config.ElasticsearchVersion; 4 | import org.junit.Test; 5 | 6 | import static org.junit.Assert.assertEquals; 7 | 8 | /** 9 | * @author Bartosz Polnik 10 | */ 11 | public class CatIndicesBuilderTest { 12 | @Test 13 | public void shouldSetApplicationJsonHeader() { 14 | Cat cat = new Cat.IndicesBuilder().build(); 15 | assertEquals("application/json", cat.getHeader("accept")); 16 | assertEquals("application/json", cat.getHeader("content-type")); 17 | } 18 | 19 | @Test 20 | public void shouldGenerateValidUriWhenIndexNotGiven() { 21 | Cat cat = new Cat.IndicesBuilder().build(); 22 | assertEquals("_cat/indices/_all", cat.getURI(ElasticsearchVersion.UNKNOWN)); 23 | } 24 | 25 | @Test 26 | public void shouldGenerateValidUriWhenIndexGiven() { 27 | Cat cat = new Cat.IndicesBuilder().addIndex("testIndex").build(); 28 | assertEquals("_cat/indices/testIndex", cat.getURI(ElasticsearchVersion.UNKNOWN)); 29 | } 30 | 31 | @Test 32 | public void shouldGenerateValidUriWhenIndexAndTypeGiven() { 33 | Cat cat = new Cat.IndicesBuilder().addIndex("testIndex").addType("testType").build(); 34 | assertEquals("_cat/indices/testIndex/testType", cat.getURI(ElasticsearchVersion.UNKNOWN)); 35 | } 36 | 37 | @Test 38 | public void shouldGenerateValidUriWhenParameterGiven() { 39 | Cat cat = new Cat.IndicesBuilder().setParameter("v", "true").build(); 40 | assertEquals("_cat/indices/_all?v=true", cat.getURI(ElasticsearchVersion.UNKNOWN)); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /jest-common/src/test/java/io/searchbox/core/CatNodesBuilderTest.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.core; 2 | 3 | import io.searchbox.client.config.ElasticsearchVersion; 4 | import org.junit.Test; 5 | 6 | import static org.junit.Assert.assertEquals; 7 | 8 | public class CatNodesBuilderTest { 9 | @Test 10 | public void shouldSetApplicationJsonHeader() { 11 | Cat cat = new Cat.NodesBuilder().build(); 12 | assertEquals("application/json", cat.getHeader("accept")); 13 | assertEquals("application/json", cat.getHeader("content-type")); 14 | } 15 | 16 | @Test 17 | public void shouldGenerateValidUriWhenIndexNotGiven() { 18 | Cat cat = new Cat.NodesBuilder().build(); 19 | assertEquals("_cat/nodes", cat.getURI(ElasticsearchVersion.UNKNOWN)); 20 | } 21 | 22 | @Test 23 | public void shouldGenerateValidUriWhenParameterGiven() { 24 | Cat cat = new Cat.NodesBuilder().setParameter("v", "true").build(); 25 | assertEquals("_cat/nodes?v=true", cat.getURI(ElasticsearchVersion.UNKNOWN)); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /jest-common/src/test/java/io/searchbox/core/CatRecoveryBuilderTest.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.core; 2 | 3 | import io.searchbox.client.config.ElasticsearchVersion; 4 | import org.junit.Test; 5 | 6 | import static org.junit.Assert.assertEquals; 7 | 8 | public class CatRecoveryBuilderTest { 9 | @Test 10 | public void shouldSetApplicationJsonHeader() { 11 | Cat cat = new Cat.RecoveryBuilder().build(); 12 | assertEquals("application/json", cat.getHeader("accept")); 13 | assertEquals("application/json", cat.getHeader("content-type")); 14 | } 15 | 16 | @Test 17 | public void shouldGenerateValidUriWhenIndexNotGiven() { 18 | Cat cat = new Cat.RecoveryBuilder().build(); 19 | assertEquals("_cat/recovery/_all", cat.getURI(ElasticsearchVersion.UNKNOWN)); 20 | } 21 | 22 | @Test 23 | public void shouldGenerateValidUriWhenIndexGiven() { 24 | Cat cat = new Cat.RecoveryBuilder().addIndex("testIndex").build(); 25 | assertEquals("_cat/recovery/testIndex", cat.getURI(ElasticsearchVersion.UNKNOWN)); 26 | } 27 | 28 | @Test 29 | public void shouldGenerateValidUriWhenParameterGiven() { 30 | Cat cat = new Cat.RecoveryBuilder().setParameter("v", "true").build(); 31 | assertEquals("_cat/recovery/_all?v=true", cat.getURI(ElasticsearchVersion.UNKNOWN)); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /jest-common/src/test/java/io/searchbox/core/CatShardsBuilderTest.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.core; 2 | 3 | import io.searchbox.client.config.ElasticsearchVersion; 4 | import org.junit.Test; 5 | 6 | import static org.junit.Assert.assertEquals; 7 | 8 | public class CatShardsBuilderTest { 9 | @Test 10 | public void shouldSetApplicationJsonHeader() { 11 | Cat cat = new Cat.ShardsBuilder().build(); 12 | assertEquals("application/json", cat.getHeader("accept")); 13 | assertEquals("application/json", cat.getHeader("content-type")); 14 | } 15 | 16 | @Test 17 | public void shouldGenerateValidUriWhenIndexNotGiven() { 18 | Cat cat = new Cat.ShardsBuilder().build(); 19 | assertEquals("_cat/shards", cat.getURI(ElasticsearchVersion.UNKNOWN)); 20 | } 21 | 22 | @Test 23 | public void shouldGenerateValidUriWhenIndexGiven() { 24 | Cat cat = new Cat.ShardsBuilder().addIndex("testIndex").build(); 25 | assertEquals("_cat/shards/testIndex", cat.getURI(ElasticsearchVersion.UNKNOWN)); 26 | } 27 | 28 | @Test 29 | public void shouldGenerateValidUriWhenParameterGiven() { 30 | Cat cat = new Cat.ShardsBuilder().setParameter("v", "true").build(); 31 | assertEquals("_cat/shards?v=true", cat.getURI(ElasticsearchVersion.UNKNOWN)); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /jest-common/src/test/java/io/searchbox/core/CountResultTest.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.core; 2 | 3 | import com.google.gson.Gson; 4 | import com.google.gson.JsonParser; 5 | import org.junit.Test; 6 | 7 | import static org.junit.Assert.assertNotNull; 8 | import static org.junit.Assert.assertNull; 9 | 10 | /** 11 | * @author cihat keser 12 | */ 13 | public class CountResultTest { 14 | 15 | String json = "{\n" + 16 | " \"count\" : 1,\n" + 17 | " \"_shards\" : {\n" + 18 | " \"total\" : 5,\n" + 19 | " \"successful\" : 5,\n" + 20 | " \"failed\" : 0\n" + 21 | " }\n" + 22 | "}"; 23 | 24 | @Test 25 | public void testGetCount() { 26 | CountResult countResult = new CountResult(new Gson()); 27 | countResult.setSucceeded(true); 28 | countResult.setJsonString(json); 29 | countResult.setJsonObject(new JsonParser().parse(json).getAsJsonObject()); 30 | countResult.setPathToResult("count"); 31 | 32 | Double count = countResult.getCount(); 33 | assertNotNull(count); 34 | } 35 | 36 | @Test 37 | public void testGetCountWhenOperationFails() { 38 | CountResult countResult = new CountResult(new Gson()); 39 | countResult.setSucceeded(false); 40 | 41 | Double count = countResult.getCount(); 42 | assertNull(count); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /jest-common/src/test/java/io/searchbox/core/ExplainTest.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.core; 2 | 3 | import io.searchbox.client.config.ElasticsearchVersion; 4 | import org.junit.Test; 5 | 6 | import static org.junit.Assert.assertEquals; 7 | import static org.junit.Assert.assertNotEquals; 8 | 9 | /** 10 | * @author Dogukan Sonmez 11 | */ 12 | public class ExplainTest { 13 | 14 | @Test 15 | public void explain() { 16 | Explain explain = new Explain.Builder("twitter", "tweet", "1", "query").build(); 17 | assertEquals("POST", explain.getRestMethodName()); 18 | assertEquals("twitter/tweet/1/_explain", explain.getURI(ElasticsearchVersion.UNKNOWN)); 19 | assertEquals("query", explain.getData(null)); 20 | } 21 | 22 | @Test 23 | public void equals(){ 24 | Explain explainUserKramer = new Explain.Builder("twitter", "tweet", "1", "{\"user\":\"kramer\"}").build(); 25 | Explain explainUserKramerDuplicate = new Explain.Builder("twitter", "tweet", "1", "{\"user\":\"kramer\"}").build(); 26 | 27 | assertEquals(explainUserKramer, explainUserKramerDuplicate); 28 | } 29 | 30 | @Test 31 | public void equalsReturnsFalseForDifferentQueries(){ 32 | Explain explainUserKramer = new Explain.Builder("twitter", "tweet", "1", "{\"user\":\"kramer\"}").build(); 33 | Explain explainUserJerry = new Explain.Builder("twitter", "tweet", "1", "{\"user\":\"jerry\"}").build(); 34 | 35 | assertNotEquals(explainUserKramer, explainUserJerry); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /jest-common/src/test/java/io/searchbox/core/GetTest.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.core; 2 | 3 | import io.searchbox.client.config.ElasticsearchVersion; 4 | import org.junit.Test; 5 | 6 | import static org.junit.Assert.assertEquals; 7 | 8 | /** 9 | * @author Dogukan Sonmez 10 | */ 11 | 12 | 13 | public class GetTest { 14 | 15 | @Test 16 | public void getDocument() { 17 | Get get = new Get.Builder("twitter", "1").type("tweet").build(); 18 | assertEquals("GET", get.getRestMethodName()); 19 | assertEquals("twitter/tweet/1", get.getURI(ElasticsearchVersion.UNKNOWN)); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /jest-common/src/test/java/io/searchbox/core/PingTest.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.core; 2 | 3 | import io.searchbox.client.config.ElasticsearchVersion; 4 | import org.junit.Test; 5 | 6 | import static org.junit.Assert.assertEquals; 7 | import static org.junit.Assert.assertNull; 8 | 9 | public class PingTest { 10 | @Test 11 | public void testBasicUriGeneration() { 12 | Ping ping = new Ping.Builder().build(); 13 | 14 | assertEquals("GET", ping.getRestMethodName()); 15 | assertNull(ping.getData(null)); 16 | assertEquals("", ping.getURI(ElasticsearchVersion.UNKNOWN)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /jest-common/src/test/java/io/searchbox/core/UpdateTest.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.core; 2 | 3 | import io.searchbox.client.config.ElasticsearchVersion; 4 | import org.junit.Test; 5 | 6 | import static org.junit.Assert.assertEquals; 7 | import static org.junit.Assert.assertNotEquals; 8 | 9 | /** 10 | * @author Dogukan Sonmez 11 | */ 12 | public class UpdateTest { 13 | 14 | @Test 15 | public void updateDocumentWithoutDoc(){ 16 | Update update = new Update.Builder(new Object()).index("twitter").type("tweet").id("1").build(); 17 | assertEquals("POST", update.getRestMethodName()); 18 | assertEquals("twitter/tweet/1/_update", update.getURI(ElasticsearchVersion.UNKNOWN)); 19 | } 20 | 21 | @Test 22 | public void equalsReturnsTrueForSamePayload(){ 23 | Update update1 = new Update.Builder("payload1").index("twitter").type("tweet").id("1").build(); 24 | Update update1Duplicate = new Update.Builder("payload1").index("twitter").type("tweet").id("1").build(); 25 | 26 | assertEquals(update1, update1Duplicate); 27 | } 28 | 29 | @Test 30 | public void equalsReturnsFalseForDifferentPayload(){ 31 | Update update1 = new Update.Builder("payload1").index("twitter").type("tweet").id("1").build(); 32 | Update update2 = new Update.Builder("payload2").index("twitter").type("tweet").id("1").build(); 33 | 34 | assertNotEquals(update1, update2); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /jest-common/src/test/java/io/searchbox/fields/FieldsStatsTest.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.fields; 2 | 3 | import com.google.gson.Gson; 4 | import io.searchbox.client.config.ElasticsearchVersion; 5 | import org.junit.Test; 6 | 7 | import java.util.Collections; 8 | import java.util.List; 9 | 10 | import static org.junit.Assert.assertEquals; 11 | 12 | public class FieldsStatsTest { 13 | static final String TEST_FIELD = "test_name"; 14 | static final String INDEX = "twitter"; 15 | static final List FIELDS = Collections.singletonList(TEST_FIELD); 16 | 17 | @Test 18 | public void testBasicUriGeneration() { 19 | FieldCapabilities fieldCapabilities = new FieldCapabilities.Builder(FIELDS).setIndex(INDEX).build(); 20 | assertEquals("POST", fieldCapabilities.getRestMethodName()); 21 | assertEquals(INDEX + "/_field_caps", fieldCapabilities.getURI(ElasticsearchVersion.UNKNOWN)); 22 | assertEquals("{\"fields\":[\"" + TEST_FIELD + "\"]}", fieldCapabilities.getData(new Gson())); 23 | } 24 | 25 | @Test 26 | public void testBasicUriGenerationNoIndex() { 27 | FieldCapabilities fieldCapabilities = new FieldCapabilities.Builder(FIELDS).build(); 28 | assertEquals("POST", fieldCapabilities.getRestMethodName()); 29 | assertEquals("_field_caps", fieldCapabilities.getURI(ElasticsearchVersion.UNKNOWN)); 30 | assertEquals("{\"fields\":[\"" + TEST_FIELD + "\"]}", fieldCapabilities.getData(new Gson())); 31 | } 32 | 33 | @Test 34 | public void testBasicUriGenerationWithLevel() { 35 | FieldCapabilities fieldCapabilities = new FieldCapabilities.Builder(FIELDS).setIndex(INDEX).setLevel("indices").build(); 36 | assertEquals("POST", fieldCapabilities.getRestMethodName()); 37 | assertEquals(INDEX + "/_field_caps?level=indices", fieldCapabilities.getURI(ElasticsearchVersion.UNKNOWN)); 38 | assertEquals("{\"fields\":[\"" + TEST_FIELD + "\"]}", fieldCapabilities.getData(new Gson())); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /jest-common/src/test/java/io/searchbox/indices/CloseIndexTest.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.indices; 2 | 3 | import io.searchbox.client.config.ElasticsearchVersion; 4 | import org.junit.Test; 5 | 6 | import static org.junit.Assert.assertEquals; 7 | import static org.junit.Assert.assertNotEquals; 8 | 9 | /** 10 | * @author cihat keser 11 | */ 12 | public class CloseIndexTest { 13 | 14 | @Test 15 | public void testBasicUrlGeneration() { 16 | CloseIndex closeIndex = new CloseIndex.Builder("twitter").build(); 17 | 18 | assertEquals("POST", closeIndex.getRestMethodName()); 19 | assertEquals("twitter/_close", closeIndex.getURI(ElasticsearchVersion.UNKNOWN)); 20 | } 21 | 22 | @Test 23 | public void equalsReturnsTrueForSameIndices() { 24 | CloseIndex closeIndex1 = new CloseIndex.Builder("twitter").build(); 25 | CloseIndex closeIndex1Duplicate = new CloseIndex.Builder("twitter").build(); 26 | 27 | assertEquals(closeIndex1, closeIndex1Duplicate); 28 | } 29 | 30 | @Test 31 | public void equalsReturnsFalseForDifferentIndices() { 32 | CloseIndex closeIndex1 = new CloseIndex.Builder("twitter").build(); 33 | CloseIndex closeIndex2 = new CloseIndex.Builder("myspace").build(); 34 | 35 | assertNotEquals(closeIndex1, closeIndex2); 36 | } 37 | 38 | } -------------------------------------------------------------------------------- /jest-common/src/test/java/io/searchbox/indices/DeleteIndexTest.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.indices; 2 | 3 | import io.searchbox.client.config.ElasticsearchVersion; 4 | import org.junit.Test; 5 | 6 | import static org.junit.Assert.assertEquals; 7 | import static org.junit.Assert.assertNotEquals; 8 | 9 | /** 10 | * @author Dogukan Sonmez 11 | */ 12 | public class DeleteIndexTest { 13 | 14 | @Test 15 | public void testBasicUriGenerationWithJustIndex() { 16 | DeleteIndex delete = new DeleteIndex.Builder("twitter").build(); 17 | 18 | assertEquals("DELETE", delete.getRestMethodName()); 19 | assertEquals("twitter", delete.getURI(ElasticsearchVersion.UNKNOWN)); 20 | } 21 | 22 | @Test 23 | public void testBasicUriGenerationWithIndexAndType() { 24 | DeleteIndex delete = new DeleteIndex.Builder("twitter").type("tweet").build(); 25 | 26 | assertEquals("DELETE", delete.getRestMethodName()); 27 | assertEquals("twitter/tweet", delete.getURI(ElasticsearchVersion.UNKNOWN)); 28 | 29 | } 30 | 31 | @Test 32 | public void equalsReturnsTrueForSameIndexAndType() { 33 | DeleteIndex delete1 = new DeleteIndex.Builder("twitter").type("tweet").build(); 34 | DeleteIndex delete1Duplicate = new DeleteIndex.Builder("twitter").type("tweet").build(); 35 | 36 | assertEquals(delete1, delete1Duplicate); 37 | } 38 | 39 | @Test 40 | public void equalsReturnsFalseForDifferentIndexAndType() { 41 | DeleteIndex delete1 = new DeleteIndex.Builder("twitter").type("tweet").build(); 42 | DeleteIndex delete2 = new DeleteIndex.Builder("twitter2").type("tweet2").build(); 43 | 44 | assertNotEquals(delete1, delete2); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /jest-common/src/test/java/io/searchbox/indices/FlushTest.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.indices; 2 | 3 | import io.searchbox.client.config.ElasticsearchVersion; 4 | import org.junit.Test; 5 | 6 | import static org.junit.Assert.assertEquals; 7 | import static org.junit.Assert.assertNotEquals; 8 | 9 | public class FlushTest { 10 | 11 | @Test 12 | public void testBasicUriGeneration() { 13 | Flush flush = new Flush.Builder().addIndex("twitter").addIndex("myspace").build(); 14 | 15 | assertEquals("POST", flush.getRestMethodName()); 16 | assertEquals("twitter%2Cmyspace/_flush", flush.getURI(ElasticsearchVersion.UNKNOWN)); 17 | } 18 | 19 | @Test 20 | public void testBasicUriGenerationWithForce() { 21 | Flush flush = new Flush.Builder().addIndex("twitter").force().build(); 22 | 23 | assertEquals("POST", flush.getRestMethodName()); 24 | assertEquals("twitter/_flush?force=true", flush.getURI(ElasticsearchVersion.UNKNOWN)); 25 | } 26 | 27 | @Test 28 | public void testBasicUriGenerationWithWaitIfOngoing() { 29 | Flush flush = new Flush.Builder().addIndex("twitter").waitIfOngoing().build(); 30 | 31 | assertEquals("POST", flush.getRestMethodName()); 32 | assertEquals("twitter/_flush?wait_if_ongoing=true", flush.getURI(ElasticsearchVersion.UNKNOWN)); 33 | } 34 | 35 | @Test 36 | public void equalsReturnsTrueForSameIndices() { 37 | Flush flush1 = new Flush.Builder().addIndex("twitter").addIndex("myspace").build(); 38 | Flush flush1Duplicate = new Flush.Builder().addIndex("twitter").addIndex("myspace").build(); 39 | 40 | assertEquals(flush1, flush1Duplicate); 41 | } 42 | 43 | @Test 44 | public void equalsReturnsFalseForDifferentIndices() { 45 | Flush flush1 = new Flush.Builder().addIndex("twitter").addIndex("myspace").build(); 46 | Flush flush2 = new Flush.Builder().addIndex("myspace").build(); 47 | 48 | assertNotEquals(flush1, flush2); 49 | } 50 | } -------------------------------------------------------------------------------- /jest-common/src/test/java/io/searchbox/indices/ForceMergeTest.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.indices; 2 | 3 | import io.searchbox.client.config.ElasticsearchVersion; 4 | import org.junit.Test; 5 | 6 | import static org.junit.Assert.assertEquals; 7 | import static org.junit.Assert.assertNotEquals; 8 | 9 | public class ForceMergeTest { 10 | 11 | @Test 12 | public void testBasicUriGeneration() { 13 | ForceMerge forceMerge = new ForceMerge.Builder().addIndex("twitter").build(); 14 | 15 | assertEquals("POST", forceMerge.getRestMethodName()); 16 | assertEquals("twitter/_forcemerge", forceMerge.getURI(ElasticsearchVersion.UNKNOWN)); 17 | } 18 | 19 | @Test 20 | public void equalsReturnsTrueForSameIndex() { 21 | ForceMerge forceMerge1 = new ForceMerge.Builder().addIndex("twitter").build(); 22 | ForceMerge forceMerge1Duplicate = new ForceMerge.Builder().addIndex("twitter").build(); 23 | 24 | assertEquals(forceMerge1, forceMerge1Duplicate); 25 | } 26 | 27 | @Test 28 | public void equalsReturnsFalseForDifferentIndex() { 29 | ForceMerge forceMerge1 = new ForceMerge.Builder().addIndex("twitter").build(); 30 | ForceMerge forceMerge2 = new ForceMerge.Builder().addIndex("myspace").build(); 31 | 32 | assertNotEquals(forceMerge1, forceMerge2); 33 | } 34 | 35 | } -------------------------------------------------------------------------------- /jest-common/src/test/java/io/searchbox/indices/IndicesExistsTest.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.indices; 2 | 3 | import io.searchbox.client.config.ElasticsearchVersion; 4 | import org.junit.Test; 5 | 6 | import static org.junit.Assert.assertEquals; 7 | import static org.junit.Assert.assertNotEquals; 8 | 9 | /** 10 | * @author ferhat sobay 11 | */ 12 | public class IndicesExistsTest { 13 | 14 | @Test 15 | public void testBasicUriGeneration() { 16 | IndicesExists indicesExists = new IndicesExists.Builder("twitter").build(); 17 | assertEquals("HEAD", indicesExists.getRestMethodName()); 18 | assertEquals("twitter", indicesExists.getURI(ElasticsearchVersion.UNKNOWN)); 19 | } 20 | 21 | @Test 22 | public void equalsReturnsTrueForSameDestination() { 23 | IndicesExists indicesExists1 = new IndicesExists.Builder("twitter").build(); 24 | IndicesExists indicesExists1Duplicate = new IndicesExists.Builder("twitter").build(); 25 | 26 | assertEquals(indicesExists1, indicesExists1Duplicate); 27 | } 28 | 29 | @Test 30 | public void equalsReturnsFalseForDifferentDestination() { 31 | IndicesExists indicesExists1 = new IndicesExists.Builder("twitter").build(); 32 | IndicesExists indicesExists2 = new IndicesExists.Builder("myspace").build(); 33 | 34 | assertNotEquals(indicesExists1, indicesExists2); 35 | } 36 | 37 | 38 | } 39 | -------------------------------------------------------------------------------- /jest-common/src/test/java/io/searchbox/indices/OpenIndexTest.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.indices; 2 | 3 | import io.searchbox.client.config.ElasticsearchVersion; 4 | import org.junit.Test; 5 | 6 | import static org.junit.Assert.assertEquals; 7 | import static org.junit.Assert.assertNotEquals; 8 | 9 | public class OpenIndexTest { 10 | 11 | @Test 12 | public void testBasicUriGeneration() { 13 | OpenIndex openIndex = new OpenIndex.Builder("twitter").build(); 14 | 15 | assertEquals("POST", openIndex.getRestMethodName()); 16 | assertEquals("twitter/_open", openIndex.getURI(ElasticsearchVersion.UNKNOWN)); 17 | } 18 | 19 | @Test 20 | public void equalsReturnsTrueForSameIndex() { 21 | OpenIndex openIndex1 = new OpenIndex.Builder("twitter").build(); 22 | OpenIndex openIndex1Duplicate = new OpenIndex.Builder("twitter").build(); 23 | 24 | assertEquals(openIndex1, openIndex1Duplicate); 25 | } 26 | 27 | @Test 28 | public void equalsReturnsFalseForDifferentIndex() { 29 | OpenIndex openIndex1 = new OpenIndex.Builder("twitter").build(); 30 | OpenIndex openIndex2 = new OpenIndex.Builder("myspace").build(); 31 | 32 | assertNotEquals(openIndex1, openIndex2); 33 | } 34 | 35 | } -------------------------------------------------------------------------------- /jest-common/src/test/java/io/searchbox/indices/OptimizeTest.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.indices; 2 | 3 | import io.searchbox.client.config.ElasticsearchVersion; 4 | import org.junit.Test; 5 | 6 | import static org.junit.Assert.assertEquals; 7 | import static org.junit.Assert.assertNotEquals; 8 | 9 | public class OptimizeTest { 10 | 11 | @Test 12 | public void testBasicUriGeneration() { 13 | Optimize optimize = new Optimize.Builder().addIndex("twitter").build(); 14 | 15 | assertEquals("POST", optimize.getRestMethodName()); 16 | assertEquals("twitter/_optimize", optimize.getURI(ElasticsearchVersion.UNKNOWN)); 17 | } 18 | 19 | @Test 20 | public void equalsReturnsTrueForSameIndex() { 21 | Optimize optimize1 = new Optimize.Builder().addIndex("twitter").build(); 22 | Optimize optimize1Duplicate = new Optimize.Builder().addIndex("twitter").build(); 23 | 24 | assertEquals(optimize1, optimize1Duplicate); 25 | } 26 | 27 | @Test 28 | public void equalsReturnsFalseForDifferentIndex() { 29 | Optimize optimize1 = new Optimize.Builder().addIndex("twitter").build(); 30 | Optimize optimize2 = new Optimize.Builder().addIndex("myspace").build(); 31 | 32 | assertNotEquals(optimize1, optimize2); 33 | } 34 | 35 | } -------------------------------------------------------------------------------- /jest-common/src/test/java/io/searchbox/indices/RefreshTest.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.indices; 2 | 3 | import io.searchbox.client.config.ElasticsearchVersion; 4 | import org.junit.Test; 5 | 6 | import static org.junit.Assert.assertEquals; 7 | import static org.junit.Assert.assertNotEquals; 8 | 9 | public class RefreshTest { 10 | 11 | @Test 12 | public void testBasicUriGeneration() { 13 | Refresh refresh = new Refresh.Builder().addIndex("twitter").addIndex("myspace").build(); 14 | 15 | assertEquals("POST", refresh.getRestMethodName()); 16 | assertEquals("twitter%2Cmyspace/_refresh", refresh.getURI(ElasticsearchVersion.UNKNOWN)); 17 | } 18 | 19 | @Test 20 | public void equalsReturnsTrueForSameIndices() { 21 | Refresh refresh1 = new Refresh.Builder().addIndex("twitter").addIndex("myspace").build(); 22 | Refresh refresh1Duplicate = new Refresh.Builder().addIndex("twitter").addIndex("myspace").build(); 23 | 24 | assertEquals(refresh1, refresh1Duplicate); 25 | } 26 | 27 | @Test 28 | public void equalsReturnsFalseForDifferentIndices() { 29 | Refresh refresh1 = new Refresh.Builder().addIndex("twitter").addIndex("myspace").build(); 30 | Refresh refresh2 = new Refresh.Builder().addIndex("twitter").addIndex("facebook").build(); 31 | 32 | assertNotEquals(refresh1, refresh2); 33 | } 34 | 35 | } -------------------------------------------------------------------------------- /jest-common/src/test/java/io/searchbox/indices/aliases/AliasExistsTest.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.indices.aliases; 2 | 3 | import io.searchbox.client.config.ElasticsearchVersion; 4 | import org.junit.Test; 5 | 6 | import static org.junit.Assert.assertEquals; 7 | 8 | public class AliasExistsTest { 9 | @Test 10 | public void testBasicUriGeneration() { 11 | AliasExists aliasExists = new AliasExists.Builder().build(); 12 | 13 | assertEquals("HEAD", aliasExists.getRestMethodName()); 14 | assertEquals("_all/_alias/*", aliasExists.getURI(ElasticsearchVersion.UNKNOWN)); 15 | } 16 | 17 | @Test 18 | public void testBasicUriGenerationWithIndex() { 19 | AliasExists aliasExists = new AliasExists.Builder().addIndex("indexName").build(); 20 | 21 | assertEquals("HEAD", aliasExists.getRestMethodName()); 22 | assertEquals("indexName/_alias/*", aliasExists.getURI(ElasticsearchVersion.UNKNOWN)); 23 | } 24 | 25 | @Test 26 | public void testBasicUriGenerationWithAlias() { 27 | AliasExists aliasExists = new AliasExists.Builder().alias("aliasName").build(); 28 | 29 | assertEquals("HEAD", aliasExists.getRestMethodName()); 30 | assertEquals("_all/_alias/aliasName", aliasExists.getURI(ElasticsearchVersion.UNKNOWN)); 31 | } 32 | 33 | @Test 34 | public void testBasicUriGenerationWithAliasAndIndex() { 35 | AliasExists aliasExists = new AliasExists.Builder().addIndex("indexName").alias("aliasName").build(); 36 | 37 | assertEquals("HEAD", aliasExists.getRestMethodName()); 38 | assertEquals("indexName/_alias/aliasName", aliasExists.getURI(ElasticsearchVersion.UNKNOWN)); 39 | } 40 | } -------------------------------------------------------------------------------- /jest-common/src/test/java/io/searchbox/indices/mapping/DeleteMappingTest.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.indices.mapping; 2 | 3 | import io.searchbox.client.config.ElasticsearchVersion; 4 | import org.junit.Test; 5 | 6 | import static org.junit.Assert.assertEquals; 7 | import static org.junit.Assert.assertNotEquals; 8 | 9 | public class DeleteMappingTest { 10 | 11 | @Test 12 | public void testBasicUriGeneration() { 13 | DeleteMapping deleteMapping = new DeleteMapping.Builder("twitter","tweet").build(); 14 | 15 | assertEquals("DELETE", deleteMapping.getRestMethodName()); 16 | assertEquals("twitter/tweet/_mapping", deleteMapping.getURI(ElasticsearchVersion.UNKNOWN)); 17 | } 18 | 19 | @Test 20 | public void equalsReturnsTrueForSameIndex() { 21 | DeleteMapping deleteMapping1 = new DeleteMapping.Builder("twitter","tweet").build(); 22 | DeleteMapping deleteMapping1Duplicate = new DeleteMapping.Builder("twitter","tweet").build(); 23 | 24 | assertEquals(deleteMapping1, deleteMapping1Duplicate); 25 | } 26 | 27 | @Test 28 | public void equalsReturnsFalseForDifferentIndex() { 29 | DeleteMapping deleteMapping1 = new DeleteMapping.Builder("twitter","tweet").build(); 30 | DeleteMapping deleteMapping2 = new DeleteMapping.Builder("twitter","myspace").build(); 31 | 32 | assertNotEquals(deleteMapping1, deleteMapping2); 33 | } 34 | 35 | } -------------------------------------------------------------------------------- /jest-common/src/test/java/io/searchbox/indices/mapping/GetMappingTest.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.indices.mapping; 2 | 3 | import io.searchbox.client.config.ElasticsearchVersion; 4 | import org.junit.Test; 5 | 6 | import static org.junit.Assert.assertEquals; 7 | import static org.junit.Assert.assertNotEquals; 8 | 9 | public class GetMappingTest { 10 | 11 | @Test 12 | public void testBasicUriGeneration() { 13 | GetMapping getMapping = new GetMapping.Builder().addIndex("twitter").build(); 14 | 15 | assertEquals("GET", getMapping.getRestMethodName()); 16 | assertEquals("twitter/_mapping", getMapping.getURI(ElasticsearchVersion.UNKNOWN)); 17 | } 18 | 19 | @Test 20 | public void equalsReturnsTrueForSameIndex() { 21 | GetMapping getMapping1 = new GetMapping.Builder().addIndex("twitter").build(); 22 | GetMapping getMapping1Duplicate = new GetMapping.Builder().addIndex("twitter").build(); 23 | 24 | assertEquals(getMapping1, getMapping1Duplicate); 25 | } 26 | 27 | @Test 28 | public void equalsReturnsFalseForDifferentIndex() { 29 | GetMapping getMapping1 = new GetMapping.Builder().addIndex("twitter").build(); 30 | GetMapping getMapping2 = new GetMapping.Builder().addIndex("myspace").build(); 31 | 32 | assertNotEquals(getMapping1, getMapping2); 33 | } 34 | 35 | } -------------------------------------------------------------------------------- /jest-common/src/test/java/io/searchbox/indices/mapping/PutMappingTest.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.indices.mapping; 2 | 3 | import io.searchbox.client.config.ElasticsearchVersion; 4 | import org.junit.Test; 5 | 6 | import static org.junit.Assert.assertEquals; 7 | import static org.junit.Assert.assertNotEquals; 8 | 9 | public class PutMappingTest { 10 | 11 | @Test 12 | public void testBasicUriGeneration() { 13 | PutMapping putMapping = new PutMapping.Builder("twitter", "tweet", "source").build(); 14 | 15 | assertEquals("PUT", putMapping.getRestMethodName()); 16 | assertEquals("twitter/tweet/_mapping", putMapping.getURI(ElasticsearchVersion.UNKNOWN)); 17 | } 18 | 19 | @Test 20 | public void equalsReturnsTrueForSameSource() { 21 | PutMapping putMapping1 = new PutMapping.Builder("twitter", "tweet", "source").build(); 22 | PutMapping putMapping1Duplicate = new PutMapping.Builder("twitter", "tweet", "source").build(); 23 | 24 | assertEquals(putMapping1, putMapping1Duplicate); 25 | } 26 | 27 | @Test 28 | public void equalsReturnsFalseForDifferentSource() { 29 | PutMapping putMapping1 = new PutMapping.Builder("twitter", "tweet", "source 1").build(); 30 | PutMapping putMapping2 = new PutMapping.Builder("twitter", "tweet", "source 2").build(); 31 | 32 | assertNotEquals(putMapping1, putMapping2); 33 | } 34 | 35 | } -------------------------------------------------------------------------------- /jest-common/src/test/java/io/searchbox/indices/script/DeleteStoredScriptTest.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.indices.script; 2 | 3 | import io.searchbox.client.config.ElasticsearchVersion; 4 | import org.junit.Before; 5 | import org.junit.Test; 6 | 7 | import static io.searchbox.indices.script.ScriptLanguage.JAVASCRIPT; 8 | import static org.hamcrest.CoreMatchers.containsString; 9 | import static org.junit.Assert.assertEquals; 10 | import static org.junit.Assert.assertThat; 11 | 12 | public class DeleteStoredScriptTest { 13 | 14 | private static final String A_NAME = "a_name"; 15 | private DeleteStoredScript script; 16 | 17 | @Before 18 | public void setUp() { 19 | DeleteStoredScript.Builder builder = new DeleteStoredScript.Builder(A_NAME).setLanguage(JAVASCRIPT); 20 | script = builder.build(); 21 | } 22 | 23 | @Test 24 | public void methodIsDelete() { 25 | assertEquals("DELETE", script.getRestMethodName()); 26 | } 27 | 28 | @Test 29 | public void scriptingLanguageIsSetIntoPath() { 30 | assertThat(script.buildURI(ElasticsearchVersion.UNKNOWN), containsString("/_scripts/")); 31 | } 32 | 33 | @Test 34 | public void nameOfTheScriptIsSetIntoPath() { 35 | assertThat(script.buildURI(ElasticsearchVersion.UNKNOWN), containsString("/_scripts/" + A_NAME)); 36 | } 37 | 38 | } -------------------------------------------------------------------------------- /jest-common/src/test/java/io/searchbox/indices/script/GetStoredScriptTest.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.indices.script; 2 | 3 | import io.searchbox.client.config.ElasticsearchVersion; 4 | import org.junit.Before; 5 | import org.junit.Test; 6 | 7 | import static io.searchbox.indices.script.ScriptLanguage.JAVASCRIPT; 8 | import static org.hamcrest.CoreMatchers.containsString; 9 | import static org.junit.Assert.assertEquals; 10 | import static org.junit.Assert.assertThat; 11 | 12 | /** 13 | * @author cihat keser 14 | */ 15 | public class GetStoredScriptTest { 16 | 17 | private static final String A_NAME = "a_name"; 18 | private GetStoredScript script; 19 | 20 | @Before 21 | public void setUp() { 22 | GetStoredScript.Builder builder = new GetStoredScript.Builder(A_NAME).setLanguage(JAVASCRIPT); 23 | script = builder.build(); 24 | } 25 | 26 | @Test 27 | public void methodIsGet() { 28 | assertEquals("GET", script.getRestMethodName()); 29 | } 30 | 31 | @Test 32 | public void scriptingLanguageIsSetIntoPath() { 33 | assertThat(script.buildURI(ElasticsearchVersion.UNKNOWN), containsString("/_scripts/")); 34 | } 35 | 36 | @Test 37 | public void nameOfTheScriptIsSetIntoPath() { 38 | assertThat(script.buildURI(ElasticsearchVersion.UNKNOWN), containsString("/_scripts/" + A_NAME)); 39 | } 40 | 41 | } -------------------------------------------------------------------------------- /jest-common/src/test/java/io/searchbox/indices/settings/UpdateSettingsTest.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.indices.settings; 2 | 3 | import io.searchbox.client.config.ElasticsearchVersion; 4 | import org.junit.Test; 5 | 6 | import static org.junit.Assert.assertEquals; 7 | import static org.junit.Assert.assertNotEquals; 8 | 9 | public class UpdateSettingsTest { 10 | 11 | @Test 12 | public void testDefaultBehaviour() { 13 | String expectedUri = "_all/_settings"; 14 | 15 | UpdateSettings updateSettings = new UpdateSettings.Builder("").build(); 16 | assertEquals(expectedUri, updateSettings.getURI(ElasticsearchVersion.UNKNOWN)); 17 | assertEquals("", updateSettings.getData(null)); 18 | assertEquals("PUT", updateSettings.getRestMethodName()); 19 | } 20 | 21 | @Test 22 | public void equalsReturnsTrueForSameSource() { 23 | UpdateSettings updateSettings1 = new UpdateSettings.Builder("source 1").build(); 24 | UpdateSettings updateSettings1Duplicate = new UpdateSettings.Builder("source 1").build(); 25 | 26 | assertEquals(updateSettings1, updateSettings1Duplicate); 27 | } 28 | 29 | @Test 30 | public void equalsReturnsFalseForDifferentSource() { 31 | UpdateSettings updateSettings1 = new UpdateSettings.Builder("source 1").build(); 32 | UpdateSettings updateSettings2 = new UpdateSettings.Builder("source 2").build(); 33 | 34 | assertNotEquals(updateSettings1, updateSettings2); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /jest-common/src/test/java/io/searchbox/indices/template/DeleteTemplateTest.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.indices.template; 2 | 3 | import io.searchbox.client.config.ElasticsearchVersion; 4 | import org.junit.Test; 5 | 6 | import static org.junit.Assert.assertEquals; 7 | import static org.junit.Assert.assertNotEquals; 8 | 9 | public class DeleteTemplateTest { 10 | 11 | @Test 12 | public void testBasicUriGeneration() { 13 | DeleteTemplate deleteTemplate = new DeleteTemplate.Builder("personal_tweet").build(); 14 | 15 | assertEquals("DELETE", deleteTemplate.getRestMethodName()); 16 | assertEquals("_template/personal_tweet", deleteTemplate.getURI(ElasticsearchVersion.UNKNOWN)); 17 | } 18 | 19 | @Test 20 | public void equalsReturnsTrueForSameTemplate() { 21 | DeleteTemplate deleteTemplate1 = new DeleteTemplate.Builder("personal_tweet").build(); 22 | DeleteTemplate deleteTemplate1Duplicate = new DeleteTemplate.Builder("personal_tweet").build(); 23 | 24 | assertEquals(deleteTemplate1, deleteTemplate1Duplicate); 25 | } 26 | 27 | @Test 28 | public void equalsReturnsFalseForDifferentTemplate() { 29 | DeleteTemplate deleteTemplate1 = new DeleteTemplate.Builder("personal_tweet").build(); 30 | DeleteTemplate deleteTemplate2 = new DeleteTemplate.Builder("company_tweet").build(); 31 | 32 | assertNotEquals(deleteTemplate1, deleteTemplate2); 33 | } 34 | 35 | } -------------------------------------------------------------------------------- /jest-common/src/test/java/io/searchbox/indices/template/GetTemplateTest.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.indices.template; 2 | 3 | import io.searchbox.client.config.ElasticsearchVersion; 4 | import org.junit.Test; 5 | 6 | import static org.junit.Assert.assertEquals; 7 | import static org.junit.Assert.assertNotEquals; 8 | 9 | public class GetTemplateTest { 10 | 11 | @Test 12 | public void testBasicUriGeneration() { 13 | GetTemplate getTemplate = new GetTemplate.Builder("personal_tweet").build(); 14 | 15 | assertEquals("GET", getTemplate.getRestMethodName()); 16 | assertEquals("_template/personal_tweet", getTemplate.getURI(ElasticsearchVersion.UNKNOWN)); 17 | } 18 | 19 | @Test 20 | public void equalsReturnsTrueForSameTemplate() { 21 | GetTemplate getTemplate1 = new GetTemplate.Builder("personal_tweet").build(); 22 | GetTemplate getTemplate1Duplicate = new GetTemplate.Builder("personal_tweet").build(); 23 | 24 | assertEquals(getTemplate1, getTemplate1Duplicate); 25 | } 26 | 27 | @Test 28 | public void equalsReturnsFalseForDifferentTemplate() { 29 | GetTemplate getTemplate1 = new GetTemplate.Builder("personal_tweet").build(); 30 | GetTemplate getTemplate2 = new GetTemplate.Builder("company_tweet").build(); 31 | 32 | assertNotEquals(getTemplate1, getTemplate2); 33 | } 34 | 35 | } -------------------------------------------------------------------------------- /jest-common/src/test/java/io/searchbox/indices/template/PutTemplateTest.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.indices.template; 2 | 3 | import io.searchbox.client.config.ElasticsearchVersion; 4 | import org.junit.Test; 5 | 6 | import static org.junit.Assert.assertEquals; 7 | import static org.junit.Assert.assertNotEquals; 8 | 9 | public class PutTemplateTest { 10 | 11 | @Test 12 | public void tesstBsicUriGeneration() { 13 | PutTemplate putTemplate = new PutTemplate.Builder("sponsored_tweet", new Object()).build(); 14 | 15 | assertEquals("PUT", putTemplate.getRestMethodName()); 16 | assertEquals("_template/sponsored_tweet", putTemplate.getURI(ElasticsearchVersion.UNKNOWN)); 17 | } 18 | 19 | @Test 20 | public void equalsReturnsTrueForSameTemplateNameAndSource() { 21 | PutTemplate putTemplate1 = new PutTemplate.Builder("sponsored_tweet", "{}").build(); 22 | PutTemplate putTemplate1Duplicate = new PutTemplate.Builder("sponsored_tweet", "{}").build(); 23 | 24 | assertEquals(putTemplate1, putTemplate1Duplicate); 25 | } 26 | 27 | @Test 28 | public void equalsReturnsFalseForDifferentTemplateSource() { 29 | PutTemplate putTemplate1 = new PutTemplate.Builder("sponsored_tweet", "{}").build(); 30 | PutTemplate putTemplate2 = new PutTemplate.Builder("sponsored_tweet", "{source}").build(); 31 | 32 | assertNotEquals(putTemplate1, putTemplate2); 33 | } 34 | 35 | } -------------------------------------------------------------------------------- /jest-common/src/test/java/io/searchbox/indices/type/TypeExistTest.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.indices.type; 2 | 3 | import io.searchbox.client.config.ElasticsearchVersion; 4 | import org.junit.Test; 5 | 6 | import static org.junit.Assert.assertEquals; 7 | import static org.junit.Assert.assertNotEquals; 8 | 9 | /** 10 | * @author happyprg(hongsgo@gmail.com) 11 | */ 12 | public class TypeExistTest { 13 | 14 | @Test 15 | public void testBasicUriGeneration_compatibleForES55() { 16 | TypeExist typeExist = new TypeExist.Builder("happyprg").addType("seohoo").build(); 17 | 18 | assertEquals("HEAD", typeExist.getRestMethodName()); 19 | assertEquals("happyprg/_mapping/seohoo", typeExist.getURI(ElasticsearchVersion.V55)); 20 | } 21 | 22 | @Test 23 | public void equalsReturnsTrueForSameDestination() { 24 | TypeExist typeExist1 = new TypeExist.Builder("twitter").addType("tweet").build(); 25 | TypeExist typeExist1Duplicate = new TypeExist.Builder("twitter").addType("tweet").build(); 26 | 27 | assertEquals(typeExist1, typeExist1Duplicate); 28 | } 29 | 30 | @Test 31 | public void equalsReturnsFalseForDifferentDestination() { 32 | TypeExist typeExist1 = new TypeExist.Builder("twitter").addType("tweet").build(); 33 | TypeExist typeExist2 = new TypeExist.Builder("myspace").addType("page").build(); 34 | 35 | assertNotEquals(typeExist1, typeExist2); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /jest-common/src/test/java/io/searchbox/snapshot/DeleteSnapshotRepositoryTest.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.snapshot; 2 | 3 | import io.searchbox.client.config.ElasticsearchVersion; 4 | import org.junit.Test; 5 | 6 | import static org.junit.Assert.assertEquals; 7 | 8 | /** 9 | * @author happyprg(hongsgo@gmail.com) 10 | */ 11 | public class DeleteSnapshotRepositoryTest { 12 | @Test 13 | public void testRepository() { 14 | String repository = "leeseohoo"; 15 | 16 | DeleteSnapshotRepository deleteSnapshotRepository = new DeleteSnapshotRepository.Builder(repository).build(); 17 | assertEquals("DELETE", deleteSnapshotRepository.getRestMethodName()); 18 | assertEquals("/_snapshot/leeseohoo", deleteSnapshotRepository.getURI(ElasticsearchVersion.UNKNOWN)); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /jest-common/src/test/java/io/searchbox/snapshot/DeleteSnapshotTest.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.snapshot; 2 | 3 | import io.searchbox.client.config.ElasticsearchVersion; 4 | import org.junit.Test; 5 | 6 | import static org.junit.Assert.assertEquals; 7 | 8 | /** 9 | * @author happyprg(hongsgo@gmail.com) 10 | */ 11 | public class DeleteSnapshotTest { 12 | 13 | private String repository = "leeseohoo"; 14 | private String snapshot = "leeseola"; 15 | 16 | @Test 17 | public void testSnapshot() { 18 | DeleteSnapshot deleteSnapshot = new DeleteSnapshot.Builder(repository, snapshot).build(); 19 | assertEquals("DELETE", deleteSnapshot.getRestMethodName()); 20 | assertEquals("/_snapshot/leeseohoo/leeseola", deleteSnapshot.getURI(ElasticsearchVersion.UNKNOWN)); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /jest-common/src/test/java/io/searchbox/snapshot/GetSnapshotRepositoryTest.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.snapshot; 2 | 3 | import io.searchbox.client.config.ElasticsearchVersion; 4 | import org.junit.Test; 5 | 6 | import java.util.Arrays; 7 | 8 | import static org.junit.Assert.assertEquals; 9 | 10 | /** 11 | * @author happyprg(hongsgo@gmail.com) 12 | */ 13 | public class GetSnapshotRepositoryTest { 14 | 15 | private String repository = "leeseohoo"; 16 | private String repository2 = "kangsungjeon"; 17 | 18 | @Test 19 | public void testRepositorySingleName() { 20 | GetSnapshotRepository getSnapshotRepository = new GetSnapshotRepository.Builder(repository).build(); 21 | assertEquals("GET", getSnapshotRepository.getRestMethodName()); 22 | assertEquals("/_snapshot/leeseohoo", getSnapshotRepository.getURI(ElasticsearchVersion.UNKNOWN)); 23 | } 24 | 25 | @Test 26 | public void testRepositoryMultipleNames() { 27 | GetSnapshotRepository getSnapshotRepository = new GetSnapshotRepository.Builder(repository) 28 | .addRepository(Arrays.asList(repository, repository2)).build(); 29 | assertEquals("/_snapshot/leeseohoo,kangsungjeon", getSnapshotRepository.getURI(ElasticsearchVersion.UNKNOWN)); 30 | } 31 | 32 | @Test 33 | public void testRepositoryAll() { 34 | GetSnapshotRepository getSnapshotRepository = new GetSnapshotRepository.Builder().build(); 35 | assertEquals("/_snapshot/_all", getSnapshotRepository.getURI(ElasticsearchVersion.UNKNOWN)); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /jest-common/src/test/java/io/searchbox/snapshot/GetSnapshotTest.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.snapshot; 2 | 3 | import io.searchbox.client.config.ElasticsearchVersion; 4 | import org.junit.Test; 5 | 6 | import java.util.Arrays; 7 | 8 | import static org.junit.Assert.assertEquals; 9 | 10 | /** 11 | * @author happyprg(hongsgo@gmail.com) 12 | */ 13 | public class GetSnapshotTest { 14 | 15 | private String repository = "kangsungjeon"; 16 | private String snapshot = "leeseohoo"; 17 | private String snapshot2 = "kangsungjeon"; 18 | 19 | @Test 20 | public void testSnapshotMultipleNames() { 21 | GetSnapshot getSnapshotRepository = new GetSnapshot.Builder(repository).addSnapshot(Arrays.asList(snapshot, snapshot2)).build(); 22 | assertEquals("/_snapshot/kangsungjeon/leeseohoo,kangsungjeon", getSnapshotRepository.getURI(ElasticsearchVersion.UNKNOWN)); 23 | } 24 | 25 | @Test 26 | public void testSnapshotAll() { 27 | GetSnapshot getSnapshotRepository = new GetSnapshot.Builder(repository).build(); 28 | assertEquals("/_snapshot/kangsungjeon/_all", getSnapshotRepository.getURI(ElasticsearchVersion.UNKNOWN)); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /jest-common/src/test/java/io/searchbox/snapshot/SnapshotStatusTest.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.snapshot; 2 | 3 | import io.searchbox.client.config.ElasticsearchVersion; 4 | import org.junit.Test; 5 | 6 | import java.util.Arrays; 7 | 8 | import static org.junit.Assert.assertEquals; 9 | 10 | /** 11 | * @author happyprg(hongsgo@gmail.com) 12 | */ 13 | public class SnapshotStatusTest { 14 | 15 | private String repository = "leeseohoo"; 16 | private String snapshot = "leeseola"; 17 | private String snapshot2 = "kangsungjeon"; 18 | 19 | @Test 20 | public void testSnapshotSingleName() { 21 | SnapshotStatus snapshotStatus = new SnapshotStatus.Builder(repository).addSnapshot(snapshot).build(); 22 | assertEquals("GET", snapshotStatus.getRestMethodName()); 23 | assertEquals("/_snapshot/leeseohoo/leeseola/_status", snapshotStatus.getURI(ElasticsearchVersion.UNKNOWN)); 24 | } 25 | 26 | @Test 27 | public void testSnapshotMultipleNames() { 28 | SnapshotStatus snapshotStatus = new SnapshotStatus.Builder(repository).addSnapshot(Arrays.asList(snapshot, snapshot2)).build(); 29 | assertEquals("/_snapshot/leeseohoo/leeseola,kangsungjeon/_status", snapshotStatus.getURI(ElasticsearchVersion.UNKNOWN)); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /jest-common/src/test/resources/io/searchbox/sample_book.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Effective Java (2nd Edition)", 3 | "author": "Joshua Bloch", 4 | "binding": "Paperback", 5 | "publisher": "Addison-Wesley", 6 | "published": "May 2008", 7 | "list_price": "$54.99", 8 | "isbn_10": "0321356683", 9 | "isbn_13": "9780321356680" 10 | } -------------------------------------------------------------------------------- /jest-droid/README.md: -------------------------------------------------------------------------------- 1 | #Jest Droid 2 | 3 | Jest Droid is the basic Android port of [Jest](https://github.com/searchbox-io/Jest). 4 | Compared to Jest, this port replaces Apache HTTP Client usages with [httpclient-android](https://hc.apache.org/httpcomponents-client-4.3.x/android-port.html) for Android SDK compatibility. 5 | 6 | Jest is a Java HTTP Rest client for [ElasticSearch](http://www.elasticsearch.org). 7 | 8 | ElasticSearch is an Open Source (Apache 2), Distributed, RESTful, Search Engine built on top of Apache Lucene. 9 | 10 | Usage 11 | --------------------- 12 | Simply add the dependency to your Gradle backed Android project. 13 | 14 | 15 | dependencies { 16 | compile 'io.searchbox:jest-droid:2.0.0' 17 | } 18 | 19 | 20 | Thanks 21 | --------------------- 22 | Thanks to [JetBrains](http://www.jetbrains.com/) for providing a license for [IntelliJ IDEA](http://www.jetbrains.com/idea/) to develop this project. 23 | 24 | 25 | Copyright and License 26 | --------------------- 27 | 28 | Copyright 2013 www.searchly.com 29 | 30 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use this work except in 31 | compliance with the License. You may obtain a copy of the License in the LICENSE file, or at: 32 | 33 | http://www.apache.org/licenses/LICENSE-2.0 34 | 35 | Unless required by applicable law or agreed to in writing, software distributed under the License is 36 | distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 37 | See the License for the specific language governing permissions and limitations under the License. 38 | -------------------------------------------------------------------------------- /jest-droid/src/main/java/com/searchly/jestdroid/DroidReapableConnectionManager.java: -------------------------------------------------------------------------------- 1 | package com.searchly.jestdroid; 2 | 3 | import io.searchbox.client.config.idle.ReapableConnectionManager; 4 | import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; 5 | 6 | import java.util.concurrent.TimeUnit; 7 | 8 | public class DroidReapableConnectionManager implements ReapableConnectionManager { 9 | 10 | private final PoolingHttpClientConnectionManager connectionManager; 11 | 12 | public DroidReapableConnectionManager(PoolingHttpClientConnectionManager connectionManager) { 13 | this.connectionManager = connectionManager; 14 | } 15 | 16 | @Override 17 | public void closeIdleConnections(long idleTimeout, TimeUnit unit) { 18 | connectionManager.closeIdleConnections(idleTimeout, unit); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /jest-droid/src/main/java/com/searchly/jestdroid/http/HttpDeleteWithEntity.java: -------------------------------------------------------------------------------- 1 | package com.searchly.jestdroid.http; 2 | 3 | import org.apache.http.client.methods.HttpDelete; 4 | import org.apache.http.client.methods.HttpEntityEnclosingRequestBaseHC4; 5 | 6 | import java.net.URI; 7 | 8 | /** 9 | * @author ferhat 10 | */ 11 | public class HttpDeleteWithEntity extends HttpEntityEnclosingRequestBaseHC4 { 12 | 13 | public HttpDeleteWithEntity() { 14 | super(); 15 | } 16 | 17 | public HttpDeleteWithEntity(URI uri) { 18 | super(); 19 | setURI(uri); 20 | } 21 | 22 | public HttpDeleteWithEntity(String uri) { 23 | super(); 24 | setURI(URI.create(uri)); 25 | } 26 | 27 | @Override 28 | public String getMethod() { 29 | return HttpDelete.METHOD_NAME; 30 | } 31 | } -------------------------------------------------------------------------------- /jest-droid/src/main/java/com/searchly/jestdroid/http/HttpGetWithEntity.java: -------------------------------------------------------------------------------- 1 | package com.searchly.jestdroid.http; 2 | 3 | /** 4 | * @author ferhat sobay 5 | */ 6 | 7 | import org.apache.http.client.methods.HttpEntityEnclosingRequestBaseHC4; 8 | import org.apache.http.client.methods.HttpGet; 9 | 10 | import java.net.URI; 11 | 12 | public class HttpGetWithEntity extends HttpEntityEnclosingRequestBaseHC4 { 13 | 14 | public HttpGetWithEntity() { 15 | super(); 16 | } 17 | 18 | public HttpGetWithEntity(URI uri) { 19 | super(); 20 | setURI(uri); 21 | } 22 | 23 | public HttpGetWithEntity(String uri) { 24 | super(); 25 | setURI(URI.create(uri)); 26 | } 27 | 28 | @Override 29 | public String getMethod() { 30 | return HttpGet.METHOD_NAME; 31 | } 32 | } -------------------------------------------------------------------------------- /jest/src/main/java/io/searchbox/client/config/idle/HttpReapableConnectionManager.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.client.config.idle; 2 | 3 | import org.apache.http.conn.HttpClientConnectionManager; 4 | import org.apache.http.nio.conn.NHttpClientConnectionManager; 5 | 6 | import java.util.concurrent.TimeUnit; 7 | 8 | public class HttpReapableConnectionManager implements ReapableConnectionManager { 9 | private final HttpClientConnectionManager connectionManager; 10 | private final NHttpClientConnectionManager nConnectionManager; 11 | 12 | public HttpReapableConnectionManager(HttpClientConnectionManager connectionManager, NHttpClientConnectionManager nConnectionManager) { 13 | if(connectionManager == null || nConnectionManager == null) throw new IllegalArgumentException(); 14 | 15 | this.connectionManager = connectionManager; 16 | this.nConnectionManager = nConnectionManager; 17 | } 18 | 19 | @Override 20 | public void closeIdleConnections(long idleTimeout, TimeUnit unit) { 21 | connectionManager.closeIdleConnections(idleTimeout, unit); 22 | nConnectionManager.closeIdleConnections(idleTimeout, unit); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /jest/src/main/java/io/searchbox/client/http/apache/HttpDeleteWithEntity.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.client.http.apache; 2 | 3 | import org.apache.http.client.methods.HttpDelete; 4 | import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; 5 | 6 | import java.net.URI; 7 | 8 | /** 9 | * @author ferhat 10 | */ 11 | public class HttpDeleteWithEntity extends HttpEntityEnclosingRequestBase { 12 | 13 | public HttpDeleteWithEntity() { 14 | super(); 15 | } 16 | 17 | public HttpDeleteWithEntity(URI uri) { 18 | super(); 19 | setURI(uri); 20 | } 21 | 22 | public HttpDeleteWithEntity(String uri) { 23 | super(); 24 | setURI(URI.create(uri)); 25 | } 26 | 27 | @Override 28 | public String getMethod() { 29 | return HttpDelete.METHOD_NAME; 30 | } 31 | } -------------------------------------------------------------------------------- /jest/src/main/java/io/searchbox/client/http/apache/HttpGetWithEntity.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.client.http.apache; 2 | 3 | /** 4 | * @author ferhat sobay 5 | */ 6 | 7 | import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; 8 | import org.apache.http.client.methods.HttpGet; 9 | 10 | import java.net.URI; 11 | 12 | public class HttpGetWithEntity extends HttpEntityEnclosingRequestBase { 13 | 14 | public HttpGetWithEntity() { 15 | super(); 16 | } 17 | 18 | public HttpGetWithEntity(URI uri) { 19 | super(); 20 | setURI(uri); 21 | } 22 | 23 | public HttpGetWithEntity(String uri) { 24 | super(); 25 | setURI(URI.create(uri)); 26 | } 27 | 28 | @Override 29 | public String getMethod() { 30 | return HttpGet.METHOD_NAME; 31 | } 32 | } -------------------------------------------------------------------------------- /jest/src/test/java/io/searchbox/cluster/GetSettingsIntegrationTest.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.cluster; 2 | 3 | 4 | import io.searchbox.client.JestResult; 5 | import io.searchbox.common.AbstractIntegrationTest; 6 | import org.elasticsearch.test.ESIntegTestCase; 7 | import org.junit.Test; 8 | 9 | import java.io.IOException; 10 | import java.util.Map; 11 | 12 | /** 13 | * @author cihat keser 14 | */ 15 | @ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.SUITE, numDataNodes = 1) 16 | public class GetSettingsIntegrationTest extends AbstractIntegrationTest { 17 | 18 | @Test 19 | public void nullSourceShouldFailOnServer() throws IOException { 20 | GetSettings getSettings = new GetSettings.Builder().build(); 21 | JestResult result = client.execute(getSettings); 22 | assertTrue(result.getErrorMessage(), result.isSucceeded()); 23 | 24 | Map settings = result.getSourceAsObject(Map.class); 25 | assertTrue(settings.containsKey("persistent")); 26 | assertTrue(settings.containsKey("transient")); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /jest/src/test/java/io/searchbox/cluster/PendingClusterTasksIntegrationTest.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.cluster; 2 | 3 | import com.google.common.collect.Iterables; 4 | import io.searchbox.client.JestResult; 5 | import io.searchbox.common.AbstractIntegrationTest; 6 | import org.elasticsearch.test.ESIntegTestCase; 7 | import org.junit.Test; 8 | 9 | import java.io.IOException; 10 | 11 | @ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.SUITE, numDataNodes = 1) 12 | public class PendingClusterTasksIntegrationTest extends AbstractIntegrationTest { 13 | @Test 14 | public void pendingClusterTasks() throws IOException { 15 | PendingClusterTasks pendingClusterTasks = new PendingClusterTasks.Builder().build(); 16 | JestResult result = client.execute(pendingClusterTasks); 17 | assertTrue(result.getErrorMessage(), result.isSucceeded()); 18 | 19 | assertTrue(result.getJsonObject().get("tasks").isJsonArray()); 20 | assertTrue(Iterables.isEmpty(result.getJsonObject().getAsJsonArray("tasks"))); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /jest/src/test/java/io/searchbox/cluster/UpdateSettingsIntegrationTest.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.cluster; 2 | 3 | 4 | import io.searchbox.client.JestResult; 5 | import io.searchbox.common.AbstractIntegrationTest; 6 | import org.elasticsearch.test.ESIntegTestCase; 7 | import org.junit.Test; 8 | 9 | import java.io.IOException; 10 | import java.util.Map; 11 | 12 | /** 13 | * @author cihat keser 14 | */ 15 | @ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.TEST, numDataNodes = 1) 16 | public class UpdateSettingsIntegrationTest extends AbstractIntegrationTest { 17 | 18 | @Test 19 | public void nullSourceShouldFailOnServer() throws IOException { 20 | UpdateSettings updateSettings = new UpdateSettings.Builder(null).build(); 21 | JestResult result = client.execute(updateSettings); 22 | assertFalse(result.isSucceeded()); 23 | } 24 | 25 | @Test 26 | public void transientSettingShouldBeUpdated() throws IOException { 27 | String source = "{\n" + 28 | " \"transient\" : {\n" + 29 | " \"indices.recovery.max_bytes_per_sec\" : \"20mb\"\n" + 30 | " }\n" + 31 | "}"; 32 | 33 | UpdateSettings updateSettings = new UpdateSettings.Builder(source).build(); 34 | JestResult result = client.execute(updateSettings); 35 | assertTrue(result.getErrorMessage(), result.isSucceeded()); 36 | 37 | Map updatedSettings = result.getSourceAsObject(Map.class); 38 | assertTrue((Boolean) updatedSettings.get("acknowledged")); 39 | Map transientSettings = (Map) updatedSettings.get("transient"); 40 | assertEquals(1, transientSettings.size()); 41 | Map persistentSettings = (Map) updatedSettings.get("persistent"); 42 | assertTrue(persistentSettings.isEmpty()); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /jest/src/test/java/io/searchbox/core/ExplainIntegrationTest.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.core; 2 | 3 | import io.searchbox.common.AbstractIntegrationTest; 4 | import org.elasticsearch.action.index.IndexRequest; 5 | import org.elasticsearch.action.support.WriteRequest; 6 | import org.elasticsearch.test.ESIntegTestCase; 7 | import org.json.JSONException; 8 | import org.junit.Test; 9 | import org.slf4j.Logger; 10 | import org.slf4j.LoggerFactory; 11 | 12 | import java.io.IOException; 13 | 14 | /** 15 | * @author Dogukan Sonmez 16 | */ 17 | @ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.SUITE, numDataNodes = 1) 18 | public class ExplainIntegrationTest extends AbstractIntegrationTest { 19 | 20 | final static Logger log = LoggerFactory.getLogger(ExplainIntegrationTest.class); 21 | 22 | @Test 23 | public void explain() throws IOException, JSONException { 24 | 25 | client().index(new IndexRequest("twitter", "tweet", "1").source("user", "tweety").setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE)).actionGet(); 26 | String query = "{\n" + 27 | " \"query\": {\n" + 28 | " \"query_string\" : {\n" + 29 | " \"query\" : \"test\"\n" + 30 | " }\n" + 31 | " }\n" + 32 | "}"; 33 | 34 | Explain explain = new Explain.Builder("twitter", "tweet", "1", query).build(); 35 | DocumentResult result = client.execute(explain); 36 | assertTrue(result.getErrorMessage(), result.isSucceeded()); 37 | assertEquals("twitter", result.getIndex()); 38 | assertEquals("tweet", result.getType()); 39 | assertEquals("1", result.getId()); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /jest/src/test/java/io/searchbox/core/PingIntegrationTest.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.core; 2 | 3 | import com.google.gson.JsonObject; 4 | import io.searchbox.client.JestResult; 5 | import io.searchbox.common.AbstractIntegrationTest; 6 | import org.elasticsearch.test.ESIntegTestCase; 7 | import org.junit.Test; 8 | 9 | import java.io.IOException; 10 | 11 | @ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.SUITE, numDataNodes = 1) 12 | public class PingIntegrationTest extends AbstractIntegrationTest { 13 | @Test 14 | public void simplePing() throws IOException { 15 | Ping ping = new Ping.Builder().build(); 16 | JestResult result = client.execute(ping); 17 | 18 | assertTrue(result.getErrorMessage(), result.isSucceeded()); 19 | final JsonObject responseJson = result.getJsonObject(); 20 | assertNotNull(responseJson.getAsJsonPrimitive("name")); 21 | assertNotNull(responseJson.getAsJsonPrimitive("cluster_name")); 22 | assertNotNull(responseJson.getAsJsonPrimitive("cluster_uuid")); 23 | assertNotNull(responseJson.getAsJsonObject("version")); 24 | assertEquals("You Know, for Search", responseJson.get("tagline").getAsString()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /jest/src/test/java/io/searchbox/core/SearchShardsIntegrationTest.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.core; 2 | 3 | import io.searchbox.client.JestResult; 4 | import io.searchbox.common.AbstractIntegrationTest; 5 | import org.elasticsearch.test.ESIntegTestCase; 6 | import org.junit.Test; 7 | 8 | import java.io.IOException; 9 | import java.util.Map; 10 | 11 | /** 12 | * @author cihat keser 13 | */ 14 | @ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.SUITE, numDataNodes = 1) 15 | public class SearchShardsIntegrationTest extends AbstractIntegrationTest { 16 | static final String INDEX = "twitter"; 17 | static final String TYPE = "tweet"; 18 | 19 | @Test 20 | public void testBasicFlow() throws IOException { 21 | SearchShards searchShards = new SearchShards.Builder() 22 | .addIndex(INDEX) 23 | .build(); 24 | JestResult result = client.execute(searchShards); 25 | assertTrue(result.getErrorMessage(), result.isSucceeded()); 26 | 27 | Map source = result.getSourceAsObject(Map.class); 28 | assertTrue(source.containsKey("nodes")); 29 | assertTrue(source.containsKey("shards")); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /jest/src/test/java/io/searchbox/core/TestArticleModel.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.core; 2 | 3 | import io.searchbox.annotations.JestId; 4 | 5 | /** 6 | * @author ferhat sobay 7 | */ 8 | public class TestArticleModel { 9 | @JestId 10 | private String id; 11 | private String name; 12 | 13 | public TestArticleModel() { 14 | } 15 | 16 | public TestArticleModel(String name) { 17 | this.name = name; 18 | } 19 | 20 | public TestArticleModel(String id, String name) { 21 | this.id = id; 22 | this.name = name; 23 | } 24 | 25 | public String getId() { 26 | return id; 27 | } 28 | 29 | public void setId(String id) { 30 | this.id = id; 31 | } 32 | 33 | public String getName() { 34 | return name; 35 | } 36 | 37 | public void setName(String name) { 38 | this.name = name; 39 | } 40 | } -------------------------------------------------------------------------------- /jest/src/test/java/io/searchbox/fields/FieldCapabilitiesIntegrationTest.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.fields; 2 | 3 | import com.google.common.collect.ImmutableMap; 4 | import io.searchbox.client.JestResult; 5 | import io.searchbox.common.AbstractIntegrationTest; 6 | import io.searchbox.core.DocumentResult; 7 | import io.searchbox.core.Index; 8 | import org.elasticsearch.test.ESIntegTestCase; 9 | import org.junit.Test; 10 | 11 | import java.io.IOException; 12 | import java.util.Collections; 13 | import java.util.List; 14 | import java.util.Map; 15 | 16 | @ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.SUITE, numDataNodes = 1) 17 | public class FieldCapabilitiesIntegrationTest extends AbstractIntegrationTest { 18 | 19 | private static final String INDEX = "twitter"; 20 | private static final String TYPE = "tweet"; 21 | private static final String TEST_FIELD = "test_name"; 22 | private static final List FIELDS = Collections.singletonList(TEST_FIELD); 23 | 24 | @Test 25 | public void testFieldStats() throws IOException { 26 | 27 | Map source = ImmutableMap.of( 28 | TEST_FIELD, "testFieldStats"); 29 | 30 | DocumentResult documentResult = client.execute( 31 | new Index.Builder(source) 32 | .index(INDEX) 33 | .type(TYPE) 34 | .refresh(true) 35 | .build() 36 | ); 37 | 38 | assertTrue(documentResult.getErrorMessage(), documentResult.isSucceeded()); 39 | 40 | FieldCapabilities fieldCapabilities = new FieldCapabilities.Builder(FIELDS).build(); 41 | 42 | JestResult fieldCapabilitiesResult = client.execute(fieldCapabilities); 43 | 44 | assertTrue(fieldCapabilitiesResult.getErrorMessage(), fieldCapabilitiesResult.isSucceeded()); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /jest/src/test/java/io/searchbox/indices/CloseIndexIntegrationTest.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.indices; 2 | 3 | import io.searchbox.client.JestResult; 4 | import io.searchbox.common.AbstractIntegrationTest; 5 | import org.elasticsearch.action.admin.indices.stats.IndicesStatsRequest; 6 | import org.elasticsearch.test.ESIntegTestCase; 7 | import org.junit.Test; 8 | 9 | import java.io.IOException; 10 | import java.util.concurrent.ExecutionException; 11 | import java.util.concurrent.TimeoutException; 12 | 13 | /** 14 | * @author cihat keser 15 | */ 16 | @ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.SUITE, numDataNodes = 2) 17 | public class CloseIndexIntegrationTest extends AbstractIntegrationTest { 18 | private static final String INDEX_NAME_1 = "test_index_1"; 19 | private static final String INDEX_NAME_2 = "test_index_2"; 20 | 21 | @Test 22 | public void testClose() throws IOException, InterruptedException, ExecutionException, TimeoutException { 23 | createIndex(INDEX_NAME_1, INDEX_NAME_2); 24 | ensureGreen(INDEX_NAME_1, INDEX_NAME_2); 25 | 26 | assertEquals( 27 | "There should be 2 indices at the start", 28 | 2, 29 | client().admin().indices().stats(new IndicesStatsRequest()).actionGet().getIndices().size() 30 | ); 31 | 32 | CloseIndex closeIndex = new CloseIndex.Builder(INDEX_NAME_2).build(); 33 | JestResult result = client.execute(closeIndex); 34 | assertTrue(result.getErrorMessage(), result.isSucceeded()); 35 | 36 | ensureGreen(INDEX_NAME_1); 37 | assertEquals( 38 | "There should be 1 index left after close operation", 39 | 1, 40 | client().admin().indices().stats(new IndicesStatsRequest()).actionGet().getIndices().size() 41 | ); 42 | } 43 | } -------------------------------------------------------------------------------- /jest/src/test/java/io/searchbox/indices/DeleteIndexIntegrationTest.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.indices; 2 | 3 | import io.searchbox.client.JestResult; 4 | import io.searchbox.common.AbstractIntegrationTest; 5 | import org.elasticsearch.test.ESIntegTestCase; 6 | import org.junit.Test; 7 | 8 | import java.io.IOException; 9 | 10 | /** 11 | * @author ferhat sobay 12 | */ 13 | @ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.SUITE, numDataNodes = 1) 14 | public class DeleteIndexIntegrationTest extends AbstractIntegrationTest { 15 | 16 | @Test 17 | public void deleteIndex() throws IOException { 18 | String indexName = "newindex"; 19 | createIndex(indexName); 20 | 21 | DeleteIndex indicesExists = new DeleteIndex.Builder(indexName).build(); 22 | JestResult result = client.execute(indicesExists); 23 | assertTrue(result.getErrorMessage(), result.isSucceeded()); 24 | } 25 | 26 | @Test 27 | public void deleteNonExistingIndex() throws IOException { 28 | DeleteIndex deleteIndex = new DeleteIndex.Builder("newindex2").build(); 29 | JestResult result = client.execute(deleteIndex); 30 | assertFalse("Delete request should fail for an index that does not exist", result.isSucceeded()); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /jest/src/test/java/io/searchbox/indices/ForceMergeIntegrationTest.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.indices; 2 | 3 | import io.searchbox.client.JestResult; 4 | import io.searchbox.common.AbstractIntegrationTest; 5 | import org.elasticsearch.action.admin.indices.stats.IndicesStatsRequest; 6 | import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse; 7 | import org.elasticsearch.test.ESIntegTestCase; 8 | import org.junit.Ignore; 9 | import org.junit.Test; 10 | 11 | import java.io.IOException; 12 | import java.util.concurrent.ExecutionException; 13 | import java.util.concurrent.TimeUnit; 14 | import java.util.concurrent.TimeoutException; 15 | 16 | /** 17 | * @author cihat keser 18 | */ 19 | @ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.SUITE, numDataNodes = 1) 20 | public class ForceMergeIntegrationTest extends AbstractIntegrationTest { 21 | 22 | // TODO find a way to confirm a previous merge request on server 23 | @Ignore 24 | @Test 25 | public void testForceMergeDefault() throws InterruptedException, ExecutionException, TimeoutException, IOException { 26 | ForceMerge forceMerge = new ForceMerge.Builder().maxNumSegments(1).build(); 27 | JestResult result = client.execute(forceMerge); 28 | assertTrue(result.getErrorMessage(), result.isSucceeded()); 29 | 30 | IndicesStatsResponse statsResponse = client().admin().indices().stats( 31 | new IndicesStatsRequest().clear().flush(true).refresh(true)).actionGet(10, TimeUnit.SECONDS); 32 | assertNotNull(statsResponse); 33 | assertNotNull(statsResponse.getTotal().getMerge()); 34 | assertEquals(1, statsResponse.getTotal().getMerge().getTotal()); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /jest/src/test/java/io/searchbox/indices/IndicesExistsIntegrationTest.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.indices; 2 | 3 | import io.searchbox.action.Action; 4 | import io.searchbox.client.JestResult; 5 | import io.searchbox.common.AbstractIntegrationTest; 6 | import org.elasticsearch.test.ESIntegTestCase; 7 | import org.junit.Before; 8 | import org.junit.Test; 9 | 10 | import java.io.IOException; 11 | 12 | /** 13 | * @author cihat keser 14 | */ 15 | @ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.SUITE, numDataNodes = 1) 16 | public class IndicesExistsIntegrationTest extends AbstractIntegrationTest { 17 | 18 | static final String INDEX_1_NAME = "osman"; 19 | static final String INDEX_2_NAME = "john"; 20 | 21 | @Before 22 | public void setup() { 23 | createIndex(INDEX_1_NAME, INDEX_2_NAME); 24 | } 25 | 26 | @Test 27 | public void multiIndexNotExists() throws IOException { 28 | Action action = new IndicesExists.Builder("qwe").addIndex("asd").build(); 29 | 30 | JestResult result = client.execute(action); 31 | assertFalse(result.isSucceeded()); 32 | } 33 | 34 | @Test 35 | public void multiIndexExists() throws IOException { 36 | Action action = new IndicesExists.Builder(INDEX_1_NAME).addIndex(INDEX_2_NAME).build(); 37 | 38 | JestResult result = client.execute(action); 39 | assertTrue(result.getErrorMessage(), result.isSucceeded()); 40 | } 41 | 42 | @Test 43 | public void indexExists() throws IOException { 44 | Action action = new IndicesExists.Builder(INDEX_1_NAME).build(); 45 | 46 | JestResult result = client.execute(action); 47 | assertTrue(result.getErrorMessage(), result.isSucceeded()); 48 | } 49 | 50 | @Test 51 | public void indexNotExists() throws IOException { 52 | Action action = new IndicesExists.Builder("nope").build(); 53 | 54 | JestResult result = client.execute(action); 55 | assertFalse(result.isSucceeded()); 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /jest/src/test/java/io/searchbox/indices/OptimizeIntegrationTest.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.indices; 2 | 3 | import io.searchbox.client.JestResult; 4 | import io.searchbox.common.AbstractIntegrationTest; 5 | import org.elasticsearch.action.admin.indices.stats.IndicesStatsRequest; 6 | import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse; 7 | import org.elasticsearch.test.ESIntegTestCase; 8 | import org.junit.Ignore; 9 | import org.junit.Test; 10 | 11 | import java.io.IOException; 12 | import java.util.concurrent.ExecutionException; 13 | import java.util.concurrent.TimeUnit; 14 | import java.util.concurrent.TimeoutException; 15 | 16 | /** 17 | * @author cihat keser 18 | */ 19 | @ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.SUITE, numDataNodes = 1) 20 | public class OptimizeIntegrationTest extends AbstractIntegrationTest { 21 | 22 | private static final String INDEX_NAME = "flush_test_index"; 23 | 24 | // TODO find a way to confirm a previous optimize request on server 25 | @Ignore 26 | @Test 27 | public void testOptimizeDefault() throws InterruptedException, ExecutionException, TimeoutException, IOException { 28 | Optimize optimize = new Optimize.Builder().maxNumSegments(1).build(); 29 | JestResult result = client.execute(optimize); 30 | assertTrue(result.getErrorMessage(), result.isSucceeded()); 31 | 32 | IndicesStatsResponse statsResponse = client().admin().indices().stats( 33 | new IndicesStatsRequest().clear().flush(true).refresh(true)).actionGet(10, TimeUnit.SECONDS); 34 | assertNotNull(statsResponse); 35 | assertNotNull(statsResponse.getTotal().getMerge()); 36 | assertEquals(1, statsResponse.getTotal().getMerge().getTotal()); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /jest/src/test/java/io/searchbox/indices/PutTemplateIntegrationTest.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.indices; 2 | 3 | 4 | import io.searchbox.client.JestResult; 5 | import io.searchbox.common.AbstractIntegrationTest; 6 | import io.searchbox.indices.template.GetTemplate; 7 | import io.searchbox.indices.template.PutTemplate; 8 | import org.elasticsearch.test.ESIntegTestCase; 9 | import org.junit.Test; 10 | 11 | import java.io.IOException; 12 | 13 | /** 14 | * @author asierdelpozo 15 | */ 16 | @ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.SUITE, numDataNodes = 1) 17 | public class PutTemplateIntegrationTest extends AbstractIntegrationTest { 18 | 19 | @Test 20 | public void testPutTemplate() throws IOException { 21 | PutTemplate putTemplate = new PutTemplate.Builder("new_template_1", 22 | "{ " + 23 | "\"template\" : \"*\"," + 24 | "\"order\" : 0," + 25 | "\"settings\" : {" + 26 | " \"number_of_shards\" : 1" + 27 | "}," + 28 | "\"mappings\" : {" + 29 | " \"type1\" : {" + 30 | " \"_source\" : { \"enabled\" : false }" + 31 | " }" + 32 | "}" + 33 | "}") 34 | .build(); 35 | 36 | JestResult result = client.execute(putTemplate); 37 | assertTrue(result.getErrorMessage(), result.isSucceeded()); 38 | 39 | GetTemplate getTemplate = new GetTemplate.Builder("new_template_1").build(); 40 | result = client.execute(getTemplate); 41 | assertTrue(result.getErrorMessage(), result.isSucceeded()); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /jest/src/test/java/io/searchbox/indices/RolloverIntegrationTest.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.indices; 2 | 3 | import io.searchbox.client.JestResult; 4 | import io.searchbox.common.AbstractIntegrationTest; 5 | import org.elasticsearch.common.collect.MapBuilder; 6 | import org.elasticsearch.test.ESIntegTestCase; 7 | import org.junit.Test; 8 | 9 | import java.io.IOException; 10 | import java.util.Map; 11 | 12 | @ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.SUITE, numDataNodes = 1) 13 | public class RolloverIntegrationTest extends AbstractIntegrationTest { 14 | 15 | private final Map rolloverConditions = new MapBuilder() 16 | .put("max_docs", "1") 17 | .put("max_age", "1d") 18 | .immutableMap(); 19 | 20 | @Test 21 | public void testRollover() throws IOException { 22 | String aliasSetting = "{ \"rollover-test-index\": {} }"; 23 | CreateIndex createIndex = new CreateIndex.Builder("rollover-test-index-000001").aliases(aliasSetting).build(); 24 | 25 | JestResult result = client.execute(createIndex); 26 | assertTrue(result.getErrorMessage(), result.isSucceeded()); 27 | 28 | Rollover rollover = new Rollover.Builder("rollover-test-index").conditions(rolloverConditions).build(); 29 | 30 | result = client.execute(rollover); 31 | assertTrue(result.getErrorMessage(), result.isSucceeded()); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /jest/src/test/java/io/searchbox/indices/script/CreateStoredScriptIntegrationTest.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.indices.script; 2 | 3 | import io.searchbox.client.JestResult; 4 | import io.searchbox.common.AbstractIntegrationTest; 5 | import org.elasticsearch.action.admin.cluster.storedscripts.GetStoredScriptResponse; 6 | import org.elasticsearch.test.ESIntegTestCase; 7 | import org.junit.Test; 8 | 9 | import java.io.IOException; 10 | 11 | import static io.searchbox.indices.script.ScriptLanguage.PAINLESS; 12 | 13 | @ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.TEST, numDataNodes = 1) 14 | public class CreateStoredScriptIntegrationTest extends AbstractIntegrationTest { 15 | 16 | @Test 17 | public void createAStoredScript() throws IOException { 18 | String name = "script-test"; 19 | String script = "int aVariable = 1; return aVariable"; 20 | 21 | CreateStoredScript createStoredScript = new CreateStoredScript.Builder(name) 22 | .setLanguage(PAINLESS) 23 | .setSource(script) 24 | .build(); 25 | JestResult result = client.execute(createStoredScript); 26 | assertTrue(result.getErrorMessage(), result.isSucceeded()); 27 | 28 | GetStoredScriptResponse getStoredScriptResponse = 29 | client().admin().cluster().prepareGetStoredScript() 30 | .setId(name).get(); 31 | assertNotNull(getStoredScriptResponse.getSource()); 32 | assertEquals(script, getStoredScriptResponse.getSource().getSource()); 33 | } 34 | } 35 | 36 | -------------------------------------------------------------------------------- /jest/src/test/java/io/searchbox/indices/script/GetStoredScriptIntegrationTest.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.indices.script; 2 | 3 | import io.searchbox.client.JestResult; 4 | import io.searchbox.common.AbstractIntegrationTest; 5 | import org.elasticsearch.action.support.master.AcknowledgedResponse; 6 | import org.elasticsearch.common.bytes.BytesArray; 7 | import org.elasticsearch.common.xcontent.XContentType; 8 | import org.junit.Test; 9 | 10 | import java.io.IOException; 11 | 12 | public class GetStoredScriptIntegrationTest extends AbstractIntegrationTest { 13 | 14 | private static final String lang = ScriptLanguage.PAINLESS.pathParameterName; 15 | private static final String SCRIPT = 16 | "{" + 17 | " \"script\": {" + 18 | " \"lang\": \"" + lang + "\"," + 19 | " \"source\": \"return 42;\"}" + 20 | "}"; 21 | 22 | @Test 23 | public void createStoredScript() throws IOException { 24 | String name = "mylilscript"; 25 | 26 | AcknowledgedResponse response = client().admin().cluster().preparePutStoredScript().setId(name) 27 | .setContent(new BytesArray(SCRIPT), XContentType.JSON).get(); 28 | assertTrue("could not create stored script on server", response.isAcknowledged()); 29 | 30 | GetStoredScript getStoredScript = new GetStoredScript.Builder(name) 31 | .setLanguage(ScriptLanguage.PAINLESS) 32 | .build(); 33 | JestResult result = client.execute(getStoredScript); 34 | assertTrue(result.getErrorMessage(), result.isSucceeded()); 35 | } 36 | } -------------------------------------------------------------------------------- /jest/src/test/java/io/searchbox/indices/settings/GetSettingsIntegrationTest.java: -------------------------------------------------------------------------------- 1 | package io.searchbox.indices.settings; 2 | 3 | import com.google.gson.JsonObject; 4 | import io.searchbox.client.JestResult; 5 | import io.searchbox.common.AbstractIntegrationTest; 6 | import org.elasticsearch.test.ESIntegTestCase; 7 | import org.junit.Test; 8 | 9 | import java.io.IOException; 10 | 11 | /** 12 | * @author cihat keser 13 | */ 14 | @ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.SUITE, numDataNodes = 1) 15 | public class GetSettingsIntegrationTest extends AbstractIntegrationTest { 16 | 17 | @Test 18 | public void testBasicFlow() throws IOException { 19 | String index = "test"; 20 | 21 | createIndex(index); 22 | ensureGreen(index); 23 | 24 | GetSettings getSettings = new GetSettings.Builder().build(); 25 | JestResult result = client.execute(getSettings); 26 | assertTrue(result.getErrorMessage(), result.isSucceeded()); 27 | 28 | assertTrue(result.isSucceeded()); 29 | System.out.println("result.getJsonString() = " + result.getJsonString()); 30 | JsonObject json = result.getJsonObject(); 31 | assertNotNull(json.getAsJsonObject(index)); 32 | assertNotNull(json.getAsJsonObject(index).getAsJsonObject("settings")); 33 | } 34 | 35 | @Test 36 | public void testForNonexistentIndex() throws IOException { 37 | String index = "test"; 38 | 39 | createIndex(index); 40 | ensureGreen(index); 41 | 42 | GetSettings getSettings = new GetSettings.Builder().addIndex("nonExisting").build(); 43 | JestResult result = client.execute(getSettings); 44 | assertFalse(result.isSucceeded()); 45 | } 46 | 47 | } -------------------------------------------------------------------------------- /jest/src/test/resources/io/searchbox/sample_book.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Effective Java (2nd Edition)", 3 | "author": "Joshua Bloch", 4 | "binding": "Paperback", 5 | "publisher": "Addison-Wesley", 6 | "published": "May 2008", 7 | "list_price": "$54.99", 8 | "isbn_10": "0321356683", 9 | "isbn_13": "9780321356680" 10 | } -------------------------------------------------------------------------------- /jest/src/test/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | # Root logger option 2 | log4j.rootLogger=INFO, stdout 3 | log4j.logger.org.elasticsearch=WARN 4 | log4j.logger.io.searchbox.client.config.discovery.NodeChecker=FATAL 5 | 6 | # Direct log messages to stdout 7 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 8 | log4j.appender.stdout.Target=System.out 9 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 10 | log4j.appender.stdout.layout.ConversionPattern=%d{HH:mm:ss} %-5p %c{1}:%L - %m%n -------------------------------------------------------------------------------- /pubring.gpg.enc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/searchbox-io/Jest/c4ded4f49a06f284fdf53cb23e84ca041c6596dd/pubring.gpg.enc -------------------------------------------------------------------------------- /secring.gpg.enc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/searchbox-io/Jest/c4ded4f49a06f284fdf53cb23e84ca041c6596dd/secring.gpg.enc -------------------------------------------------------------------------------- /settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | ossrh 6 | ${env.SONATYPE_USERNAME} 7 | ${env.SONATYPE_PASSWORD} 8 | 9 | 10 | 11 | 12 | ossrh 13 | 14 | true 15 | 16 | 17 | gpg 18 | ${env.GPG_PASSPHRASE} 19 | false 20 | ./local.pubring.gpg 21 | ./local.secring.gpg 22 | 23 | 24 | 25 | --------------------------------------------------------------------------------