Skip to content

Instantly share code, notes, and snippets.

@dadoonet
Created December 3, 2012 17:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dadoonet/4196419 to your computer and use it in GitHub Desktop.
Save dadoonet/4196419 to your computer and use it in GitHub Desktop.
GET _mapping test case
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