本文整理汇总了Java中org.elasticsearch.common.xcontent.support.XContentMapValues类的典型用法代码示例。如果您正苦于以下问题:Java XContentMapValues类的具体用法?Java XContentMapValues怎么用?Java XContentMapValues使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
XContentMapValues类属于org.elasticsearch.common.xcontent.support包,在下文中一共展示了XContentMapValues类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: assertMappingOnMaster
import org.elasticsearch.common.xcontent.support.XContentMapValues; //导入依赖的package包/类
/**
* Waits for the given mapping type to exists on the master node.
*/
public void assertMappingOnMaster(final String index, final String type, final String... fieldNames) throws Exception {
GetMappingsResponse response = client().admin().indices().prepareGetMappings(index).setTypes(type).get();
ImmutableOpenMap<String, MappingMetaData> mappings = response.getMappings().get(index);
assertThat(mappings, notNullValue());
MappingMetaData mappingMetaData = mappings.get(type);
assertThat(mappingMetaData, notNullValue());
Map<String, Object> mappingSource = mappingMetaData.getSourceAsMap();
assertFalse(mappingSource.isEmpty());
assertTrue(mappingSource.containsKey("properties"));
for (String fieldName : fieldNames) {
Map<String, Object> mappingProperties = (Map<String, Object>) mappingSource.get("properties");
if (fieldName.indexOf('.') != -1) {
fieldName = fieldName.replace(".", ".properties.");
}
assertThat("field " + fieldName + " doesn't exists in mapping " + mappingMetaData.source().string(), XContentMapValues.extractValue(fieldName, mappingProperties), notNullValue());
}
}
示例2: parse
import org.elasticsearch.common.xcontent.support.XContentMapValues; //导入依赖的package包/类
@Override
public MetadataFieldMapper.Builder parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException {
Builder builder = new Builder(parserContext.type());
for (Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext();) {
Map.Entry<String, Object> entry = iterator.next();
String fieldName = entry.getKey();
Object fieldNode = entry.getValue();
if (fieldName.equals("type")) {
builder.type(fieldNode.toString());
iterator.remove();
} else if (FIELDDATA.match(fieldName)) {
// for bw compat only
Map<String, String> fieldDataSettings = SettingsLoader.Helper.loadNestedFromMap(nodeMapValue(fieldNode, "fielddata"));
if (fieldDataSettings.containsKey("loading")) {
builder.eagerGlobalOrdinals("eager_global_ordinals".equals(fieldDataSettings.get("loading")));
}
iterator.remove();
} else if (fieldName.equals("eager_global_ordinals")) {
builder.eagerGlobalOrdinals(XContentMapValues.nodeBooleanValue(fieldNode, "eager_global_ordinals"));
iterator.remove();
}
}
return builder;
}
示例3: testCompletionMultiField
import org.elasticsearch.common.xcontent.support.XContentMapValues; //导入依赖的package包/类
public void testCompletionMultiField() throws Exception {
assertAcked(
client().admin().indices().prepareCreate("my-index")
.addMapping("my-type", createMappingSource("completion"))
);
GetMappingsResponse getMappingsResponse = client().admin().indices().prepareGetMappings("my-index").get();
MappingMetaData mappingMetaData = getMappingsResponse.mappings().get("my-index").get("my-type");
assertThat(mappingMetaData, not(nullValue()));
Map<String, Object> mappingSource = mappingMetaData.sourceAsMap();
Map aField = ((Map) XContentMapValues.extractValue("properties.a", mappingSource));
assertThat(aField.size(), equalTo(6));
assertThat(aField.get("type").toString(), equalTo("completion"));
assertThat(aField.get("fields"), notNullValue());
Map bField = ((Map) XContentMapValues.extractValue("properties.a.fields.b", mappingSource));
assertThat(bField.size(), equalTo(1));
assertThat(bField.get("type").toString(), equalTo("keyword"));
client().prepareIndex("my-index", "my-type", "1").setSource("a", "complete me").setRefreshPolicy(IMMEDIATE).get();
SearchResponse countResponse = client().prepareSearch("my-index").setSize(0).setQuery(matchQuery("a.b", "complete me")).get();
assertThat(countResponse.getHits().getTotalHits(), equalTo(1L));
}
示例4: testIpMultiField
import org.elasticsearch.common.xcontent.support.XContentMapValues; //导入依赖的package包/类
public void testIpMultiField() throws Exception {
assertAcked(
client().admin().indices().prepareCreate("my-index")
.addMapping("my-type", createMappingSource("ip"))
);
GetMappingsResponse getMappingsResponse = client().admin().indices().prepareGetMappings("my-index").get();
MappingMetaData mappingMetaData = getMappingsResponse.mappings().get("my-index").get("my-type");
assertThat(mappingMetaData, not(nullValue()));
Map<String, Object> mappingSource = mappingMetaData.sourceAsMap();
Map aField = ((Map) XContentMapValues.extractValue("properties.a", mappingSource));
assertThat(aField.size(), equalTo(2));
assertThat(aField.get("type").toString(), equalTo("ip"));
assertThat(aField.get("fields"), notNullValue());
Map bField = ((Map) XContentMapValues.extractValue("properties.a.fields.b", mappingSource));
assertThat(bField.size(), equalTo(1));
assertThat(bField.get("type").toString(), equalTo("keyword"));
client().prepareIndex("my-index", "my-type", "1").setSource("a", "127.0.0.1").setRefreshPolicy(IMMEDIATE).get();
SearchResponse countResponse = client().prepareSearch("my-index").setSize(0).setQuery(matchQuery("a.b", "127.0.0.1")).get();
assertThat(countResponse.getHits().getTotalHits(), equalTo(1L));
}
示例5: SnapshotsSettings
import org.elasticsearch.common.xcontent.support.XContentMapValues; //导入依赖的package包/类
public SnapshotsSettings(RiverSettings settings) {
super();
if (settings.settings().containsKey(RIVERNAME)) {
@SuppressWarnings({ "unchecked" })
Map<String, Object> snapshotterSettings = (Map<String, Object>) settings.settings().get(RIVERNAME);
this.repository = XContentMapValues.nodeStringValue(snapshotterSettings.get("repository"), "my_backup");
this.indices = XContentMapValues.nodeStringValue(snapshotterSettings.get("indices"), "_all");
this.includeGlobalState = XContentMapValues.nodeBooleanValue(snapshotterSettings.get("include_global_state"), false);
this.frequency = TimeValue.parseTimeValue(XContentMapValues.nodeStringValue(snapshotterSettings.get("frequency"), "24h"), TimeValue.timeValueMinutes(60));
if (snapshotterSettings.get("purgeAfter") != null && snapshotterSettings.get("purgeAfter").toString().length() > 0) {
this.purgeAfter = TimeValue.parseTimeValue(XContentMapValues.nodeStringValue(snapshotterSettings.get("purgeAfter"), "240h"), TimeValue.timeValueHours(240));
} else {
this.purgeAfter = null;
}
this.setPurgeIndicesMustMatch(XContentMapValues.nodeBooleanValue(snapshotterSettings.get("purge_indices_must_match"), true));
} else {
this.repository = "my_backup";
this.indices = "_all";
this.includeGlobalState = false;
this.frequency = TimeValue.timeValueHours(24);
this.purgeAfter = null; // no purging by default
this.setPurgeIndicesMustMatch(true);
}
}
示例6: parse
import org.elasticsearch.common.xcontent.support.XContentMapValues; //导入依赖的package包/类
@SuppressWarnings({"unchecked", "rawtypes"})
@Override
public Mapper.Builder parse(String name, Map<String, Object> mapping, ParserContext parserContext) {
StandardnumberMapper.Builder builder = new Builder(name, service);
Iterator<Map.Entry<String, Object>> iterator = mapping.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<String, Object> entry = iterator.next();
String fieldName = entry.getKey();
Object fieldNode = entry.getValue();
switch (fieldName) {
case "standardnumbers" :
builder.settingsBuilder.putArray("standardnumbers", XContentMapValues.nodeStringArrayValue(fieldNode));
iterator.remove();
break;
default:
break;
}
}
return builder;
}
示例7: createFeeder
import org.elasticsearch.common.xcontent.support.XContentMapValues; //导入依赖的package包/类
private Feeder createFeeder(String riverType, String riverName, RiverSettings riverSettings) {
JDBCFeeder feeder = null;
try {
Map<String, Object> spec = (Map<String, Object>) riverSettings.settings().get("jdbc");
Map<String, String> loadedSettings = new JsonSettingsLoader().load(jsonBuilder().map(spec).string());
Settings mySettings = settingsBuilder().put(loadedSettings).build();
String strategy = XContentMapValues.nodeStringValue(spec.get("strategy"), "simple");
RiverFlow riverFlow = RiverServiceLoader.findRiverFlow(strategy);
logger.debug("found river flow class {} for strategy {}", riverFlow.getClass().getName(), strategy);
feeder = riverFlow.getFeeder();
logger.debug("spec = {} settings = {}", spec, mySettings.getAsMap());
feeder.setName(riverName)
.setType(riverType)
.setSpec(spec).setSettings(mySettings);
} catch (IOException e) {
logger.error(e.getMessage(), e);
}
return feeder;
}
示例8: createRiverContext
import org.elasticsearch.common.xcontent.support.XContentMapValues; //导入依赖的package包/类
@Override
protected void createRiverContext(String riverType, String riverName, Map<String, Object> mySettings) throws IOException {
super.createRiverContext(riverType, riverName, mySettings);
// defaults for column strategy
String columnCreatedAt = XContentMapValues.nodeStringValue(mySettings.get("created_at"), "created_at");
String columnUpdatedAt = XContentMapValues.nodeStringValue(mySettings.get("updated_at"), "updated_at");
String columnDeletedAt = XContentMapValues.nodeStringValue(mySettings.get("deleted_at"), null);
boolean columnEscape = XContentMapValues.nodeBooleanValue(mySettings.get("column_escape"), true);
TimeValue lastRunTimeStampOverlap = XContentMapValues.nodeTimeValue(mySettings.get("last_run_timestamp_overlap"),
TimeValue.timeValueSeconds(0));
riverContext
.columnCreatedAt(columnCreatedAt)
.columnUpdatedAt(columnUpdatedAt)
.columnDeletedAt(columnDeletedAt)
.columnEscape(columnEscape)
.setLastRunTimeStampOverlap(lastRunTimeStampOverlap);
}
示例9: testAttachments
import org.elasticsearch.common.xcontent.support.XContentMapValues; //导入依赖的package包/类
@Test
public void testAttachments() throws Exception{
Map<String, Object> settings = settings("/river-imap-attachments.json");
final Properties props = new Properties();
final String user = XContentMapValues.nodeStringValue(settings.get("user"), null);
final String password = XContentMapValues.nodeStringValue(settings.get("password"), null);
for (final Map.Entry<String, Object> entry : settings.entrySet()) {
if (entry != null && entry.getKey().startsWith("mail.")) {
props.setProperty(entry.getKey(), String.valueOf(entry.getValue()));
}
}
registerRiver("imap_river", "river-imap-attachments.json");
final Session session = Session.getInstance(props);
final Store store = session.getStore();
store.connect(user, password);
checkStoreForTestConnection(store);
final Folder inbox = store.getFolder("INBOX");
inbox.open(Folder.READ_WRITE);
final MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(EMAIL_TO));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(EMAIL_USER_ADDRESS));
message.setSubject(EMAIL_SUBJECT + "::attachment test");
message.setSentDate(new Date());
BodyPart bp = new MimeBodyPart();
bp.setText("Text");
Multipart mp = new MimeMultipart();
mp.addBodyPart(bp);
bp = new MimeBodyPart();
DataSource ds = new ByteArrayDataSource(this.getClass().getResourceAsStream("/httpclient-tutorial.pdf"), AttachmentMapperTest.APPLICATION_PDF);
bp.setDataHandler(new DataHandler(ds));
bp.setFileName("httpclient-tutorial.pdf");
mp.addBodyPart(bp);
message.setContent(mp);
inbox.appendMessages(new Message[]{message});
IMAPUtils.close(inbox);
IMAPUtils.close(store);
//let the river index
Thread.sleep(20*1000);
esSetup.client().admin().indices().refresh(new RefreshRequest()).actionGet();
SearchResponse searchResponse = esSetup.client().prepareSearch("imapriverdata").setTypes("mail").execute().actionGet();
Assert.assertEquals(1, searchResponse.getHits().totalHits());
//BASE64 content httpclient-tutorial.pdf
Assert.assertTrue(searchResponse.getHits().hits()[0].getSourceAsString().contains(AttachmentMapperTest.PDF_BASE64_DETECTION));
searchResponse = esSetup.client().prepareSearch("imapriverdata").addFields("*").setTypes("mail").setQuery(QueryBuilders.matchPhraseQuery("attachments.content.content", PDF_CONTENT_TO_SEARCH)).execute().actionGet();
Assert.assertEquals(1, searchResponse.getHits().totalHits());
Assert.assertEquals(1, searchResponse.getHits().hits()[0].field("attachments.content.content").getValues().size());
Assert.assertEquals("HttpClient Tutorial", searchResponse.getHits().hits()[0].field("attachments.content.title").getValue().toString());
Assert.assertEquals("application/pdf", searchResponse.getHits().hits()[0].field("attachments.content.content_type").getValue().toString());
Assert.assertTrue(searchResponse.getHits().hits()[0].field("attachments.content.content").getValue().toString().contains(PDF_CONTENT_TO_SEARCH));
}
示例10: isStarted
import org.elasticsearch.common.xcontent.support.XContentMapValues; //导入依赖的package包/类
private boolean isStarted(){
// Refresh index before querying it.
client.admin().indices().prepareRefresh("_river").execute().actionGet();
GetResponse isStartedGetResponse = client.prepareGet("_river", riverName().name(), "_s3status").execute().actionGet();
try{
if (!isStartedGetResponse.isExists()){
XContentBuilder xb = jsonBuilder().startObject()
.startObject("amazon-s3")
.field("feedname", feedDefinition.getFeedname())
.field("status", "STARTED").endObject()
.endObject();
client.prepareIndex("_river", riverName.name(), "_s3status").setSource(xb).execute();
return true;
} else {
String status = (String)XContentMapValues.extractValue("amazon-s3.status", isStartedGetResponse.getSourceAsMap());
if ("STOPPED".equals(status)){
return false;
}
}
} catch (Exception e){
logger.warn("failed to get status for " + riverName().name() + ", throttling....", e);
}
return true;
}
示例11: buildArrayFromSettings
import org.elasticsearch.common.xcontent.support.XContentMapValues; //导入依赖的package包/类
/**
* Extract array from settings (array or ; delimited String)
* @param settings Settings
* @param path Path to settings definition
* @return Array of settings
*/
@SuppressWarnings("unchecked")
public static String[] buildArrayFromSettings(Map<String, Object> settings, String path){
String[] includes;
// We manage comma separated format and arrays
if (XContentMapValues.isArray(XContentMapValues.extractValue(path, settings))) {
List<String> includesarray = (List<String>) XContentMapValues.extractValue(path, settings);
int i = 0;
includes = new String[includesarray.size()];
for (String include : includesarray) {
includes[i++] = trimAllWhitespace(include);
}
} else {
String includedef = (String) XContentMapValues.extractValue(path, settings);
includes = Strings.commaDelimitedListToStringArray(trimAllWhitespace(includedef));
}
String[] uniquelist = removeDuplicateStrings(includes);
return uniquelist;
}
示例12: buildArrayFromSettings
import org.elasticsearch.common.xcontent.support.XContentMapValues; //导入依赖的package包/类
/**
* Extract array from settings (array or ; delimited String)
* @param settings Settings
* @param path Path to settings definition
* @return Array of settings
*/
@SuppressWarnings("unchecked")
public static String[] buildArrayFromSettings(Map<String, Object> settings, String path){
String[] includes;
// We manage comma separated format and arrays
if (XContentMapValues.isArray(XContentMapValues.extractValue(path, settings))) {
List<String> includesarray = (List<String>) XContentMapValues.extractValue(path, settings);
int i = 0;
includes = new String[includesarray.size()];
for (String include : includesarray) {
includes[i++] = Strings.trimAllWhitespace(include);
}
} else {
String includedef = (String) XContentMapValues.extractValue(path, settings);
includes = Strings.commaDelimitedListToStringArray(Strings.trimAllWhitespace(includedef));
}
String[] uniquelist = Strings.removeDuplicateStrings(includes);
return uniquelist;
}
示例13: isStarted
import org.elasticsearch.common.xcontent.support.XContentMapValues; //导入依赖的package包/类
private boolean isStarted(){
// Refresh index before querying it.
client.admin().indices().prepareRefresh("_river").execute().actionGet();
GetResponse isStartedGetResponse = client.prepareGet("_river", riverName().name(), "_drivestatus").execute().actionGet();
try{
if (!isStartedGetResponse.isExists()){
XContentBuilder xb = jsonBuilder().startObject()
.startObject("google-drive")
.field("feedname", feedDefinition.getFeedname())
.field("status", "STARTED").endObject()
.endObject();
client.prepareIndex("_river", riverName.name(), "_drivestatus").setSource(xb).execute();
return true;
} else {
String status = (String)XContentMapValues.extractValue("google-drive.status", isStartedGetResponse.getSourceAsMap());
if ("STOPPED".equals(status)){
return false;
}
}
} catch (Exception e){
logger.warn("failed to get status for " + riverName().name() + ", throttling....", e);
}
return true;
}
示例14: parseConfig
import org.elasticsearch.common.xcontent.support.XContentMapValues; //导入依赖的package包/类
private void parseConfig() {
if (settings.settings().containsKey("wildfly")) {
Map<String, Object> wildflySettings = (Map<String, Object>) settings.settings().get("wildfly");
this.username = XContentMapValues.nodeStringValue(wildflySettings.get("user"), null);
this.password = XContentMapValues.nodeStringValue(wildflySettings.get("user"), null);
this.host = XContentMapValues.nodeStringValue(wildflySettings.get("host"), null);
this.port = XContentMapValues.nodeIntegerValue(wildflySettings.get("port"), 9999);
this.scheduleSeconds = XContentMapValues.nodeIntegerValue(wildflySettings.get("schedule"), 1);
}
else
{
logger.error("invalid wildfly plugin configuration");
}
if (settings.settings().containsKey("index")) {
Map<String, Object> indexSettings = (Map<String, Object>) settings.settings().get("index");
indexName = XContentMapValues.nodeStringValue(indexSettings.get("index"), riverName.name());
typeName = XContentMapValues.nodeStringValue(indexSettings.get("type"), "status");
}
else
{
logger.error("invalid wildfly plugin configuration");
}
}
示例15: nodeToAttributeList
import org.elasticsearch.common.xcontent.support.XContentMapValues; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private List<Attribute> nodeToAttributeList(Object obj, List<Attribute> defaultValue) {
if (null != obj && XContentMapValues.isArray(obj)) {
List<Attribute> res = new ArrayList<Attribute>();
for (Object o : (List<Object>) obj) {
if (o instanceof String) {
res.add(new Attribute(o.toString()));
} else if (o instanceof Map) {
Map<String, Object> oMap = (Map<String, Object>) o;
if (oMap.containsKey("name")) {
if (oMap.containsKey("transform")) {
res.add(new Attribute(oMap.get("name").toString(), oMap.get("transform").toString()));
} else {
res.add(new Attribute(oMap.get("name").toString()));
}
}
}
}
return res;
}
return defaultValue;
}