org.elasticsearch.common.xcontent.XContentFactory Java Examples
The following examples show how to use
org.elasticsearch.common.xcontent.XContentFactory.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CreateIndexRequest.java From crate with Apache License 2.0 | 6 votes |
/** * Adds mapping that will be added when the index gets created. * * @param type The mapping type * @param source The mapping source */ @SuppressWarnings("unchecked") public CreateIndexRequest mapping(String type, Map source) { if (mappings.containsKey(type)) { throw new IllegalStateException("mappings for type \"" + type + "\" were already defined"); } // wrap it in a type map if its not if (source.size() != 1 || !source.containsKey(type)) { source = MapBuilder.<String, Object>newMapBuilder().put(type, source).map(); } try { XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON); builder.map(source); return mapping(type, builder); } catch (IOException e) { throw new ElasticsearchGenerationException("Failed to generate [" + source + "]", e); } }
Example #2
Source File: DocIndexMetaDataTest.java From crate with Apache License 2.0 | 6 votes |
@Test public void testCopyToWithoutMetaIndices() throws Exception { // regression test... this mapping used to cause an NPE XContentBuilder builder = XContentFactory.jsonBuilder() .startObject() .startObject("properties") .startObject("description") .field("type", "string") .array("copy_to", "description_ft") .endObject() .startObject("description_ft") .field("type", "string") .field("analyzer", "english") .endObject() .endObject() .endObject(); IndexMetaData metaData = getIndexMetaData("test1", builder); DocIndexMetaData md = newMeta(metaData, "test1"); assertThat(md.indices().size(), is(1)); assertThat(md.indices().keySet().iterator().next(), is(new ColumnIdent("description_ft"))); }
Example #3
Source File: MetricProfileRepositoryImpl.java From adaptive-alerting with Apache License 2.0 | 6 votes |
@Override public Boolean profilingExists(Map<String, String> tags) { try { List<BytesReference> refList = new ArrayList<>(); XContentBuilder xContent = XContentFactory.jsonBuilder(); xContent.map(tags); refList.add(BytesReference.bytes(xContent)); PercolateQueryBuilder percolateQuery = new PercolateQueryBuilder(PercolatorMetricProfiling.QUERY_KEYWORD, refList, XContentType.JSON); val boolQueryBuilder = new BoolQueryBuilder(); boolQueryBuilder.filter(percolateQuery); val searchSourceBuilder = elasticsearchUtil.getSourceBuilder(boolQueryBuilder); searchSourceBuilder.timeout(new TimeValue(elasticSearchProperties.getConfig().getConnectionTimeout())); searchSourceBuilder.size(500); val searchRequest = new SearchRequest().source(searchSourceBuilder).indices(METRIC_PROFILING_INDEX); val searchResponse = legacyElasticSearchClient.search(searchRequest, RequestOptions.DEFAULT); return searchResponse.getHits().getHits().length > 0; } catch (IOException e) { log.error("Error ES lookup", e); throw new RuntimeException(e); } }
Example #4
Source File: ElasticSearch.java From javabase with Apache License 2.0 | 6 votes |
/** * 创建mapping分词IK索引 * Elasticsearch的mapping一旦创建,只能增加字段,而不能修改已经mapping的字段 * @param indexType * @return */ private static XContentBuilder createIKMapping(String indexType,String field) { XContentBuilder mapping = null; try { mapping = XContentFactory.jsonBuilder().startObject() // 索引库名(类似数据库中的表) .startObject(indexType) //匹配全部 .startObject("properties") //根据只对content这个Fields分词 .startObject(field).field("type","string").field("store","no") .field("term_vector","with_positions_offsets").field("analyzer","ik_max_word") .field("search_analyzer","ik_max_word").field("include_in_all","true").field("boost",8) .endObject() .endObject() .endObject().endObject(); } catch (IOException e) { log.error("创建mapping分词IK索引 error"+e.getLocalizedMessage()); } return mapping; }
Example #5
Source File: BaseElasticSearchMapping.java From ElasticUtils with MIT License | 6 votes |
public XContentBuilder internalGetMapping() throws IOException { // Configure the RootObjectMapper: RootObjectMapper.Builder rootObjectMapperBuilder = getRootObjectBuilder(); // Populate the Settings: Settings.Builder settingsBuilder = getSettingsBuilder(); //new Mapping(arg0, arg1, arg2, arg3)getSourceTransforms(), // Build the Mapping: Mapping mapping = new Mapping( version, rootObjectMapperBuilder.build(new Mapper.BuilderContext(settingsBuilder.build(), new ContentPath(1))), getMetaDataFieldMappers(), getMeta()); // Turn it into JsonXContent: return mapping.toXContent(XContentFactory.jsonBuilder().startObject(), new ToXContent.MapParams(emptyMap())).endObject(); }
Example #6
Source File: StoredFeature.java From elasticsearch-learning-to-rank with Apache License 2.0 | 6 votes |
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(); builder.field(NAME.getPreferredName(), name); builder.field(PARAMS.getPreferredName(), queryParams); builder.field(TEMPLATE_LANGUAGE.getPreferredName(), templateLanguage); if (templateAsString) { builder.field(TEMPLATE.getPreferredName(), template); } else { builder.field(TEMPLATE.getPreferredName()); // it's ok to use NamedXContentRegistry.EMPTY because we don't really parse we copy the structure... XContentParser parser = XContentFactory.xContent(template).createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, template); builder.copyCurrentStructure(parser); } builder.endObject(); return builder; }
Example #7
Source File: Job.java From zentity with Apache License 2.0 | 6 votes |
/** * Submit a search query to Elasticsearch. * * @param indexName The name of the index to search. * @param query The query to search. * @return The search response returned by Elasticsearch. * @throws IOException */ private SearchResponse search(String indexName, String query) throws IOException { SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); SearchModule searchModule = new SearchModule(Settings.EMPTY, false, Collections.emptyList()); try (XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser(new NamedXContentRegistry(searchModule .getNamedXContents()), DeprecationHandler.THROW_UNSUPPORTED_OPERATION, query)) { searchSourceBuilder.parseXContent(parser); } SearchRequestBuilder searchRequestBuilder = new SearchRequestBuilder(client, SearchAction.INSTANCE); searchRequestBuilder.setIndices(indexName).setSource(searchSourceBuilder); if (this.searchAllowPartialSearchResults != null) searchRequestBuilder.setAllowPartialSearchResults(this.searchAllowPartialSearchResults); if (this.searchBatchedReduceSize != null) searchRequestBuilder.setBatchedReduceSize(this.searchBatchedReduceSize); if (this.searchMaxConcurrentShardRequests != null) searchRequestBuilder.setMaxConcurrentShardRequests(this.searchMaxConcurrentShardRequests); if (this.searchPreFilterShardSize != null) searchRequestBuilder.setPreFilterShardSize(this.searchPreFilterShardSize); if (this.searchPreference != null) searchRequestBuilder.setPreference(this.searchPreference); if (this.searchRequestCache != null) searchRequestBuilder.setRequestCache(this.searchRequestCache); if (this.maxTimePerQuery != null) searchRequestBuilder.setTimeout(TimeValue.parseTimeValue(this.maxTimePerQuery, "timeout")); return searchRequestBuilder.execute().actionGet(); }
Example #8
Source File: BaseElasticSearchMapping.java From ElasticUtils with MIT License | 6 votes |
public XContentBuilder internalGetMapping() throws IOException { // Configure the RootObjectMapper: RootObjectMapper.Builder rootObjectMapperBuilder = getRootObjectBuilder(); // Populate the Settings: Settings.Builder settingsBuilder = getSettingsBuilder(); //new Mapping(arg0, arg1, arg2, arg3)getSourceTransforms(), // Build the Mapping: Mapping mapping = new Mapping( version, rootObjectMapperBuilder.build(new Mapper.BuilderContext(settingsBuilder.build(), new ContentPath(1))), getMetaDataFieldMappers(), getMeta()); // Turn it into JsonXContent: return mapping.toXContent(XContentFactory.jsonBuilder().startObject(), new ToXContent.MapParams(emptyMap())).endObject(); }
Example #9
Source File: ArrayMapperTest.java From crate with Apache License 2.0 | 6 votes |
@Test public void testParseDynamicEmptyArray() throws Exception { String mapping = Strings.toString(XContentFactory.jsonBuilder() .startObject().startObject(TYPE).startObject("properties") .endObject().endObject().endObject()); DocumentMapper mapper = mapper(INDEX, mapping); // parse source with empty array BytesReference bytesReference = BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .array("new_array_field") .endObject()); SourceToParse sourceToParse = new SourceToParse(INDEX, "abc", bytesReference, XContentType.JSON); ParsedDocument doc = mapper.parse(sourceToParse); assertThat(doc.docs().get(0).getField("new_array_field"), is(nullValue())); assertThat(mapper.mappers().getMapper("new_array_field"), is(nullValue())); }
Example #10
Source File: WrapperQueryParser.java From Elasticsearch with Apache License 2.0 | 6 votes |
@Override public Query parse(QueryParseContext parseContext) throws IOException, QueryParsingException { XContentParser parser = parseContext.parser(); XContentParser.Token token = parser.nextToken(); if (token != XContentParser.Token.FIELD_NAME) { throw new QueryParsingException(parseContext, "[wrapper] query malformed"); } String fieldName = parser.currentName(); if (!fieldName.equals("query")) { throw new QueryParsingException(parseContext, "[wrapper] query malformed"); } parser.nextToken(); byte[] querySource = parser.binaryValue(); try (XContentParser qSourceParser = XContentFactory.xContent(querySource).createParser(querySource)) { final QueryParseContext context = new QueryParseContext(parseContext.index(), parseContext.indexQueryParserService()); context.reset(qSourceParser); Query result = context.parseInnerQuery(); parser.nextToken(); parseContext.combineNamedQueries(context); return result; } }
Example #11
Source File: CrudDemo.java From javabase with Apache License 2.0 | 6 votes |
/** * https://github.com/medcl/elasticsearch-analysis-pinyin/tree/v1.7.5 * pinyin配置分析器 * @return */ public static String getIndexPinYinSetting() throws IOException { XContentBuilder mapping = XContentFactory.jsonBuilder() .startObject() .startObject("analysis") .startObject("analyzer") .startObject("pinyin_analyzer") .field("tokenizer", "my_pinyin") .array("filter","nGram","word_delimiter") .endObject() .endObject() .startObject("tokenizer") .startObject("my_pinyin") .field("type", "pinyin") .field("first_letter","prefix") .field("padding_char","") .endObject() .endObject() .endObject() .endObject(); return mapping.string(); }
Example #12
Source File: ElasticSearchUtilImpl.java From metacat with Apache License 2.0 | 6 votes |
/** * {@inheritDoc} */ @Override public void softDelete(final String type, final String id, final MetacatRequestContext metacatRequestContext) { try { RETRY_ES_PUBLISH.call(() -> { final XContentBuilder builder = XContentFactory.contentBuilder(contentType); builder.startObject().field(ElasticSearchDoc.Field.DELETED, true) .field(ElasticSearchDoc.Field.TIMESTAMP, java.time.Instant.now().toEpochMilli()) .field(ElasticSearchDoc.Field.USER, metacatRequestContext.getUserName()).endObject(); client.prepareUpdate(esIndex, type, id) .setRetryOnConflict(NO_OF_CONFLICT_RETRIES).setDoc(builder).get(esCallTimeout); ensureMigrationByCopy(type, Collections.singletonList(id)); return null; }); } catch (Exception e) { handleException("ElasticSearchUtil.softDelete", type, id, e, Metrics.CounterElasticSearchDelete.getMetricName()); } }
Example #13
Source File: LicenseKeyTest.java From crate with Apache License 2.0 | 6 votes |
@Test public void testLicenceKeyFromXContent() throws IOException { XContentBuilder builder = XContentFactory.jsonBuilder(); // reflects the logic used to process custom metadata in the cluster state builder.startObject(); builder.startObject(LicenseKey.WRITEABLE_TYPE) .field("license_key", LICENSE_KEY) .endObject(); builder.endObject(); XContentParser parser = JsonXContent.JSON_XCONTENT.createParser(xContentRegistry(), DeprecationHandler.THROW_UNSUPPORTED_OPERATION, BytesReference.toBytes(BytesReference.bytes(builder))); parser.nextToken(); // start object LicenseKey licenseKey2 = LicenseKey.fromXContent(parser); assertEquals(createLicenseKey(), licenseKey2); // a metadata custom must consume the surrounded END_OBJECT token, no token must be left assertThat(parser.nextToken(), nullValue()); }
Example #14
Source File: ReindexInvokerWithIndexingErrorsTest.java From elasticsearch-reindex-tool with Apache License 2.0 | 6 votes |
public XContentBuilder createStrictMappingDefinition() { try { // @formatter:off //How to enable it in intellij see it here: http://stackoverflow.com/questions/3375307/how-to-disable-code-formatting-for-some-part-of-the-code-using-comments return XContentFactory.jsonBuilder() .startObject() .field("dynamic", "strict") .startObject("properties") .startObject("field1") .field("type", "string") .endObject() .endObject() .endObject(); // @formatter:off } catch (IOException e) { throw new RuntimeException("Failed building index mappingDef", e); } }
Example #15
Source File: Alias.java From Elasticsearch with Apache License 2.0 | 6 votes |
/** * Associates a filter to the alias */ public Alias filter(QueryBuilder filterBuilder) { if (filterBuilder == null) { this.filter = null; return this; } try { XContentBuilder builder = XContentFactory.jsonBuilder(); filterBuilder.toXContent(builder, ToXContent.EMPTY_PARAMS); builder.close(); this.filter = builder.string(); return this; } catch (IOException e) { throw new ElasticsearchGenerationException("Failed to build json for alias request", e); } }
Example #16
Source File: StandardnumberMappingTests.java From elasticsearch-plugin-bundle with GNU Affero General Public License v3.0 | 6 votes |
public void testNonStandardnumber() throws Exception { String mapping = copyToStringFromClasspath("mapping.json"); DocumentMapper docMapper = createIndex("some_index") .mapperService().documentMapperParser() .parse("someType", new CompressedXContent(mapping)); String sampleText = "Hello world"; BytesReference json = BytesReference.bytes(XContentFactory.jsonBuilder() .startObject().field("someField", sampleText).endObject()); SourceToParse sourceToParse = SourceToParse.source("some_index", "someType", "1", json, XContentType.JSON); ParseContext.Document doc = docMapper.parse(sourceToParse).rootDoc(); assertEquals(0, doc.getFields("someField").length); // re-parse it String builtMapping = docMapper.mappingSource().string(); logger.warn("testNonStandardnumber: built mapping =" + builtMapping); DocumentMapper docMapper2 = createIndex("some_index2") .mapperService().documentMapperParser() .parse("someType", new CompressedXContent(builtMapping)); json = BytesReference.bytes(XContentFactory.jsonBuilder().startObject() .field("someField", sampleText).endObject()); sourceToParse = SourceToParse.source("some_index2", "someType", "1", json, XContentType.JSON); doc = docMapper2.parse(sourceToParse).rootDoc(); assertEquals(0, doc.getFields("someField").length); }
Example #17
Source File: Test.java From dht-spider with MIT License | 6 votes |
public static void createIndex() throws Exception{ XContentBuilder builder = XContentFactory.jsonBuilder(); builder.startObject(); { builder.startObject("properties"); { builder.startObject("message"); { builder.field("type", "text"); builder.field("analyzer", "ik_max_word"); builder.field("search_analyzer", "ik_max_word"); } builder.endObject(); } builder.endObject(); } builder.endObject(); CreateIndexRequest request = new CreateIndexRequest("twitter"); request.mapping(builder); client.indices().create(request, RequestOptions.DEFAULT); }
Example #18
Source File: ElasticSearchManualTest.java From tutorials with MIT License | 6 votes |
@Test public void givenContentBuilder_whenHelpers_thanIndexJson() throws IOException { XContentBuilder builder = XContentFactory.jsonBuilder() .startObject() .field("fullName", "Test") .field("salary", "11500") .field("age", "10") .endObject(); IndexRequest indexRequest = new IndexRequest("people"); indexRequest.source(builder); IndexResponse response = client.index(indexRequest, RequestOptions.DEFAULT); assertEquals(Result.CREATED, response.getResult()); }
Example #19
Source File: SystemMonitorTarget.java From fess with Apache License 2.0 | 6 votes |
private void appendElasticsearchStats(final StringBuilder buf) { String stats = null; try { final FessEsClient esClient = ComponentUtil.getFessEsClient(); final NodesStatsResponse response = esClient.admin().cluster().prepareNodesStats().all().execute().actionGet(10000L); final XContentBuilder builder = XContentFactory.jsonBuilder(); builder.startObject(); response.toXContent(builder, ToXContent.EMPTY_PARAMS); builder.endObject(); builder.flush(); try (OutputStream out = builder.getOutputStream()) { stats = ((ByteArrayOutputStream) out).toString(Constants.UTF_8); } } catch (final Exception e) { logger.debug("Failed to access Elasticsearch stats.", e); } buf.append("\"elasticsearch\":").append(stats).append(','); }
Example #20
Source File: IndicesStatsResponse.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override public String toString() { try { XContentBuilder builder = XContentFactory.jsonBuilder().prettyPrint(); builder.startObject(); toXContent(builder, EMPTY_PARAMS); builder.endObject(); return builder.string(); } catch (IOException e) { return "{ \"error\" : \"" + e.getMessage() + "\"}"; } }
Example #21
Source File: CompressedXContent.java From Elasticsearch with Apache License 2.0 | 5 votes |
/** * Create a {@link CompressedXContent} out of a {@link ToXContent} instance. */ public CompressedXContent(ToXContent xcontent, XContentType type, ToXContent.Params params) throws IOException { BytesStreamOutput bStream = new BytesStreamOutput(); OutputStream compressedStream = CompressorFactory.defaultCompressor().streamOutput(bStream); CRC32 crc32 = new CRC32(); OutputStream checkedStream = new CheckedOutputStream(compressedStream, crc32); try (XContentBuilder builder = XContentFactory.contentBuilder(type, checkedStream)) { builder.startObject(); xcontent.toXContent(builder, params); builder.endObject(); } this.bytes = bStream.bytes().toBytes(); this.crc32 = (int) crc32.getValue(); assertConsistent(); }
Example #22
Source File: PutRepositoryRequest.java From Elasticsearch with Apache License 2.0 | 5 votes |
/** * Sets the repository settings. * * @param source repository settings * @return this request */ public PutRepositoryRequest settings(Map<String, Object> source) { try { XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON); builder.map(source); settings(builder.string()); } catch (IOException e) { throw new ElasticsearchGenerationException("Failed to generate [" + source + "]", e); } return this; }
Example #23
Source File: DocIndexMetaDataTest.java From crate with Apache License 2.0 | 5 votes |
@Test public void testSchemaWithNotNullGeneratedColumn() throws Exception { XContentBuilder builder = XContentFactory.jsonBuilder() .startObject() .startObject("_meta") .startObject("generated_columns") .field("week", "date_trunc('week', ts)") .endObject() .startObject("constraints") .array("not_null", "week") .endObject() .endObject() .startObject("properties") .startObject("ts").field("type", "date").endObject() .startObject("week").field("type", "long").endObject() .endObject() .endObject(); IndexMetaData metaData = getIndexMetaData("test1", builder); DocIndexMetaData md = newMeta(metaData, "test1"); assertThat(md.columns().size(), is(2)); Reference week = md.references().get(new ColumnIdent("week")); assertThat(week, Matchers.notNullValue()); assertThat(week.isNullable(), is(false)); assertThat(week, instanceOf(GeneratedReference.class)); assertThat(((GeneratedReference) week).formattedGeneratedExpression(), is("date_trunc('week', ts)")); assertThat(((GeneratedReference) week).generatedExpression(), isFunction("date_trunc", isLiteral("week"), isReference("ts"))); assertThat(((GeneratedReference) week).referencedReferences(), contains(isReference("ts"))); }
Example #24
Source File: AbstractRestActionTest.java From elasticsearch-inout-plugin with Apache License 2.0 | 5 votes |
/** * Convert an XContent object to a Java map * @param toXContent * @return * @throws IOException */ public static Map<String, Object> toMap(ToXContent toXContent) throws IOException { XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON); toXContent.toXContent(builder, ToXContent.EMPTY_PARAMS); return XContentFactory.xContent(XContentType.JSON).createParser( builder.string()).mapOrderedAndClose(); }
Example #25
Source File: RestoreSnapshotRequest.java From Elasticsearch with Apache License 2.0 | 5 votes |
/** * Sets repository-specific restore settings * <p> * See repository documentation for more information. * * @param source repository-specific snapshot settings * @return this request */ public RestoreSnapshotRequest settings(Map<String, Object> source) { try { XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON); builder.map(source); settings(builder.string()); } catch (IOException e) { throw new ElasticsearchGenerationException("Failed to generate [" + source + "]", e); } return this; }
Example #26
Source File: ElasticKibanaConsumer.java From baleen with Apache License 2.0 | 5 votes |
private XContentBuilder createEntityMapping() throws IOException { // Just specify common values, and ones that won't be Keyword strings return XContentFactory.jsonBuilder() .startObject() .startObject(entityType) .startObject(ES_PARENT) .field(ES_TYPE, documentType) .endObject() .startObject(ES_PROPERTIES) .startObject("value") .field(ES_TYPE, ES_TYPE_KEYWORD) .endObject() .startObject("begin") .field(ES_TYPE, ES_TYPE_INTEGER) .endObject() .startObject("end") .field(ES_TYPE, ES_TYPE_INTEGER) .endObject() .startObject("confidence") .field(ES_TYPE, ES_TYPE_DOUBLE) .endObject() .startObject("geoJson") .field(ES_TYPE, ES_TYPE_GEOSHAPE) .endObject() .startObject("timestampStart") .field(ES_TYPE, ES_TYPE_DATE) .field("format", "epoch_second") .endObject() .startObject("timestampStop") .field(ES_TYPE, ES_TYPE_DATE) .field("format", "epoch_second") .endObject() .startObject("processedAt") .field(ES_TYPE, ES_TYPE_DATE) .field("format", "epoch_millis") .endObject() .endObject() .endObject() .endObject(); }
Example #27
Source File: DocIndexMetaDataTest.java From crate with Apache License 2.0 | 5 votes |
@Test public void testExtractColumnDefinitionsFromEmptyIndex() throws Exception { XContentBuilder builder = XContentFactory.jsonBuilder() .startObject() .startObject(Constants.DEFAULT_MAPPING_TYPE) .endObject() .endObject(); IndexMetaData metaData = getIndexMetaData("test2", builder); DocIndexMetaData md = newMeta(metaData, "test2"); assertThat(md.columns(), hasSize(0)); }
Example #28
Source File: WriterProjector.java From Elasticsearch with Apache License 2.0 | 5 votes |
public DocWriter(OutputStream outputStream, Set<CollectExpression<Row, ?>> collectExpressions, Map<String, Object> overwrites) throws IOException { this.outputStream = outputStream; this.collectExpressions = collectExpressions; this.overwrites = overwrites; builder = XContentFactory.jsonBuilder(outputStream); }
Example #29
Source File: ElasticsearchUtil.java From SpringBootLearn with Apache License 2.0 | 5 votes |
/** * 创建索引以及映射mapping,并给索引某些字段指定iK分词,以后向该索引中查询时,就会用ik分词。 * @Author lihaodong * @Description * @Date 20:19 2018/12/21 * @Param [indexName, esType] * @return boolean **/ public static boolean createIndex(String indexName, String esType) { if (!isIndexExist(indexName)) { log.info("Index is not exits!"); } //创建映射 XContentBuilder mapping = null; try { mapping = XContentFactory.jsonBuilder() .startObject() .startObject("properties") // .startObject("m_id").field("type","keyword").endObject() // title:字段名, type:文本类型 analyzer :分词器类型 .startObject("id").field("type", "text").field("analyzer", "standard").endObject() //该字段添加的内容,查询时将会使用ik_smart分词 .startObject("name").field("type", "text").field("analyzer", "standard").endObject() //ik_smart ik_max_word standard .startObject("message").field("type", "text").field("analyzer", "standard").endObject() .startObject("price").field("type", "float").endObject() .startObject("creatDate").field("type", "date").endObject() .endObject() .endObject(); } catch (IOException e) { log.error("执行建立失败:{}",e.getMessage()); } //index:索引名 type:类型名 PutMappingRequest putmap = Requests.putMappingRequest(indexName).type(esType).source(mapping); //创建索引 client.admin().indices().prepareCreate(indexName).execute().actionGet(); //为索引添加映射 PutMappingResponse indexresponse = client.admin().indices().putMapping(putmap).actionGet(); log.info("执行建立成功?" + indexresponse.isAcknowledged()); return indexresponse.isAcknowledged(); }
Example #30
Source File: GeoJSONUtils.java From Elasticsearch with Apache License 2.0 | 5 votes |
public static Shape map2Shape(Map<String, Object> geoJSONMap) { try { return geoJSONString2Shape(XContentFactory.jsonBuilder().map(geoJSONMap).string()); } catch (Throwable e) { throw new IllegalArgumentException(String.format(Locale.ENGLISH, "Cannot convert Map \"%s\" to shape", geoJSONMap), e); } }