Created
December 3, 2012 17:11
-
-
Save dadoonet/4196419 to your computer and use it in GitHub Desktop.
GET _mapping test case
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.elasticsearchfr.tests; | |
import java.io.File; | |
import org.elasticsearch.action.get.GetResponse; | |
import org.elasticsearch.common.io.FileSystemUtils; | |
import org.elasticsearch.common.logging.ESLogger; | |
import org.elasticsearch.common.logging.ESLoggerFactory; | |
import org.elasticsearch.common.settings.ImmutableSettings; | |
import org.elasticsearch.common.settings.Settings; | |
import org.elasticsearch.node.Node; | |
import org.elasticsearch.node.NodeBuilder; | |
import org.junit.Assert; | |
import org.junit.BeforeClass; | |
import org.junit.Test; | |
/** | |
* Testing Get Mapping in Java | |
* @See https://groups.google.com/forum/?hl=fr&fromgroups=#!topic/elasticsearch/IDZQKxgzR3s | |
* @author David Pilato (aka dadoonet) | |
*/ | |
public class ES002GetMappingTest { | |
protected final ESLogger logger = ESLoggerFactory.getLogger(this.getClass().getName()); | |
/** | |
* Elasticsearch node | |
*/ | |
protected static Node node; | |
@BeforeClass | |
public static void setUpBeforeClass() throws Exception { | |
if (node == null) { | |
// We remove old data before launching tests | |
removeOldDataDir(); | |
// Then we start our node for tests | |
node = NodeBuilder.nodeBuilder().node(); | |
// We wait now for the yellow (or green) status | |
node.client().admin().cluster().prepareHealth() | |
.setWaitForYellowStatus().execute().actionGet(); | |
Assert.assertNotNull(node); | |
Assert.assertFalse(node.isClosed()); | |
} | |
} | |
private static void removeOldDataDir() throws Exception { | |
Settings settings = ImmutableSettings.settingsBuilder().loadFromClasspath("elasticsearch.yml").build(); | |
// First we delete old datas... | |
File dataDir = new File(settings.get("path.data")); | |
if (dataDir.exists()) { | |
FileSystemUtils.deleteRecursively(dataDir, true); | |
} | |
} | |
/** | |
* @throws Exception | |
*/ | |
@Test | |
public void getMapping() throws Exception { | |
node.client().prepareIndex("es002index", "type1").setSource("{\"email\" : \"abc@otherdomain.com\", \"firstname\" : \"abc\"}").execute().actionGet(); | |
node.client().admin().indices().prepareRefresh().execute().actionGet(); | |
GetResponse gr = node.client().prepareGet("es002index", "type1", "_mapping").execute().actionGet(); | |
Assert.assertNotNull(gr); | |
Assert.assertNotNull(gr.getSourceAsString()); | |
logger.info("Result is : {}", gr.getSourceAsString()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment