當前位置: 首頁>>代碼示例>>Java>>正文


Java MappingMetaData.sourceAsMap方法代碼示例

本文整理匯總了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));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:24,代碼來源:MultiFieldsIntegrationIT.java

示例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));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:24,代碼來源:MultiFieldsIntegrationIT.java

示例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));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:30,代碼來源:MultiFieldsIntegrationIT.java

示例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));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:36,代碼來源:MultiFieldsIntegrationIT.java

示例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));
}
 
開發者ID:obourgain,項目名稱:elasticsearch-http,代碼行數:34,代碼來源:PutMappingActionHandlerTest.java

示例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));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:57,代碼來源:MultiFieldsIntegrationIT.java


注:本文中的org.elasticsearch.cluster.metadata.MappingMetaData.sourceAsMap方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。