本文整理汇总了Java中org.elasticsearch.cluster.metadata.MappingMetaData.sourceAsMap方法的典型用法代码示例。如果您正苦于以下问题:Java MappingMetaData.sourceAsMap方法的具体用法?Java MappingMetaData.sourceAsMap怎么用?Java MappingMetaData.sourceAsMap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.elasticsearch.cluster.metadata.MappingMetaData
的用法示例。
在下文中一共展示了MappingMetaData.sourceAsMap方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testCompletionMultiField
import org.elasticsearch.cluster.metadata.MappingMetaData; //导入方法依赖的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));
}
示例2: testIpMultiField
import org.elasticsearch.cluster.metadata.MappingMetaData; //导入方法依赖的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));
}
示例3: testGeoPointMultiField
import org.elasticsearch.cluster.metadata.MappingMetaData; //导入方法依赖的package包/类
public void testGeoPointMultiField() throws Exception {
assertAcked(
client().admin().indices().prepareCreate("my-index")
.addMapping("my-type", createMappingSource("geo_point"))
);
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));
logger.info("Keys: {}", aField.keySet());
assertThat(aField.size(), equalTo(2));
assertThat(aField.get("type").toString(), equalTo("geo_point"));
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"));
GeoPoint point = new GeoPoint(51, 19);
client().prepareIndex("my-index", "my-type", "1").setSource("a", point.toString()).setRefreshPolicy(IMMEDIATE).get();
SearchResponse countResponse = client().prepareSearch("my-index").setSize(0)
.setQuery(constantScoreQuery(geoDistanceQuery("a").point(51, 19).distance(50, DistanceUnit.KILOMETERS)))
.get();
assertThat(countResponse.getHits().getTotalHits(), equalTo(1L));
countResponse = client().prepareSearch("my-index").setSize(0).setQuery(matchQuery("a.b", point.geohash())).get();
assertThat(countResponse.getHits().getTotalHits(), equalTo(1L));
}
示例4: testTokenCountMultiField
import org.elasticsearch.cluster.metadata.MappingMetaData; //导入方法依赖的package包/类
public void testTokenCountMultiField() throws Exception {
assertAcked(
client().admin().indices().prepareCreate("my-index")
.addMapping("my-type", XContentFactory.jsonBuilder().startObject().startObject("my-type")
.startObject("properties")
.startObject("a")
.field("type", "token_count")
.field("analyzer", "simple")
.startObject("fields")
.startObject("b")
.field("type", "keyword")
.endObject()
.endObject()
.endObject()
.endObject()
.endObject().endObject())
);
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(3));
assertThat(aField.get("type").toString(), equalTo("token_count"));
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", "my tokens").setRefreshPolicy(IMMEDIATE).get();
SearchResponse countResponse = client().prepareSearch("my-index").setSize(0).setQuery(matchQuery("a.b", "my tokens")).get();
assertThat(countResponse.getHits().getTotalHits(), equalTo(1L));
}
示例5: should_put_mapping
import org.elasticsearch.cluster.metadata.MappingMetaData; //导入方法依赖的package包/类
@Test
public void should_put_mapping() throws Exception {
String type = "test_type";
PutMappingRequest request = new PutMappingRequest(THE_INDEX)
.ignoreConflicts(true)
.type(type)
.source("{\n" +
" \"properties\" : {\n" +
" \"message\" : {\"type\" : \"string\", \"store\" : true }\n" +
" }\n" +
"}");
httpClient.admin().indices().putMapping(request).get();
GetMappingsResponse getMappingsResponse = transportClient.admin().indices().getMappings(new GetMappingsRequest().indices(THE_INDEX)).actionGet();
ImmutableOpenMap<String, MappingMetaData> mapping = getMappingsResponse.getMappings().get(THE_INDEX);
Assertions.assertThat(mapping.containsKey(type)).isTrue();
MappingMetaData mappingMetaData = mapping.get(type);
Map<String, Object> map = mappingMetaData.sourceAsMap();
Assertions.assertThat(map.containsKey("properties")).isTrue();
Assertions.assertThat(map.get("properties")).isInstanceOf(Map.class);
Map<String, Object> properties = (Map) map.get("properties");
Assertions.assertThat(properties.get("message")).isInstanceOf(Map.class);
Map<String, Object> message = (Map<String, Object>) properties.get("message");
Assertions.assertThat(message).contains(MapEntry.entry("type", "string"), MapEntry.entry("store", true));
}
示例6: testMultiFields
import org.elasticsearch.cluster.metadata.MappingMetaData; //导入方法依赖的package包/类
public void testMultiFields() throws Exception {
assertAcked(
client().admin().indices().prepareCreate("my-index")
.addMapping("my-type", createTypeSource())
);
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 titleFields = ((Map) XContentMapValues.extractValue("properties.title.fields", mappingSource));
assertThat(titleFields.size(), equalTo(1));
assertThat(titleFields.get("not_analyzed"), notNullValue());
assertThat(((Map)titleFields.get("not_analyzed")).get("type").toString(), equalTo("keyword"));
client().prepareIndex("my-index", "my-type", "1")
.setSource("title", "Multi fields")
.setRefreshPolicy(IMMEDIATE)
.get();
SearchResponse searchResponse = client().prepareSearch("my-index")
.setQuery(matchQuery("title", "multi"))
.get();
assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L));
searchResponse = client().prepareSearch("my-index")
.setQuery(matchQuery("title.not_analyzed", "Multi fields"))
.get();
assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L));
assertAcked(
client().admin().indices().preparePutMapping("my-index").setType("my-type")
.setSource(createPutMappingSource())
);
getMappingsResponse = client().admin().indices().prepareGetMappings("my-index").get();
mappingMetaData = getMappingsResponse.mappings().get("my-index").get("my-type");
assertThat(mappingMetaData, not(nullValue()));
mappingSource = mappingMetaData.sourceAsMap();
assertThat(((Map) XContentMapValues.extractValue("properties.title", mappingSource)).size(), equalTo(2));
titleFields = ((Map) XContentMapValues.extractValue("properties.title.fields", mappingSource));
assertThat(titleFields.size(), equalTo(2));
assertThat(titleFields.get("not_analyzed"), notNullValue());
assertThat(((Map)titleFields.get("not_analyzed")).get("type").toString(), equalTo("keyword"));
assertThat(titleFields.get("uncased"), notNullValue());
assertThat(((Map)titleFields.get("uncased")).get("analyzer").toString(), equalTo("whitespace"));
client().prepareIndex("my-index", "my-type", "1")
.setSource("title", "Multi fields")
.setRefreshPolicy(IMMEDIATE)
.get();
searchResponse = client().prepareSearch("my-index")
.setQuery(matchQuery("title.uncased", "Multi"))
.get();
assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L));
}