use of co.elastic.clients.elasticsearch._types.mapping.Property in project weicoder by wdcode.
the class ElasticSearch method create.
/**
* 创建索引
*
* @param <E>
* @param index 索引对象
* @throws IOException
*/
public void create(Index index) {
try {
// 创建索引
// CreateIndexRequest request = new CreateIndexRequest(getIndexName(index));
CreateIndexRequest request = CreateIndexRequest.of(r -> r.index(getIndexName(index)).settings(s -> s.numberOfRoutingShards(index.shards()).numberOfReplicas(index.replica())));
// 创建索引对象类型
// Map<String, Object> properties = Maps.newMap();
Map<String, Property> properties = Maps.newMap();
// 获得所有索引字段 根据数据类型设置
// BeanUtil.getFields(index.getClass())
// .forEach(f -> properties.put(f.getName(), Maps.newMap("type", f.getType())));
BeanUtil.getFields(index.getClass()).forEach(f -> properties.put(f.getName(), Property.of(p -> p.searchAsYouType(v -> v.name(f.getName())))));
// f.getType())));xxxxxxx
// request.mapping(JsonEngine.toJson(Maps.newMap("properties", properties)));//, XContentType.JSON
request.mappings().properties().putAll(properties);
// 创建索引
// client.indices().create(request, RequestOptions.DEFAULT);
client.indices().create(c -> c.index("products"));
} catch (IOException e) {
Logs.error(e);
}
}
use of co.elastic.clients.elasticsearch._types.mapping.Property in project elasticsearch-java by elastic.
the class BehaviorsTest method testShortcutProperty.
@Test
public void testShortcutProperty() {
// All-in-one: a variant, wrapping a single-key dictionary with a shortcut property
String json = "{\"term\":{\"some-field\":\"some-value\"}}";
Query q = fromJson(json, Query.class);
assertEquals("some-field", q.term().field());
assertEquals("some-value", q.term().value().stringValue());
}
use of co.elastic.clients.elasticsearch._types.mapping.Property in project elasticsearch-java by elastic.
the class RequestTest method testGetMapping.
@Test
public void testGetMapping() throws Exception {
// See also VariantsTest.testNestedTaggedUnionWithDefaultTag()
// and https://github.com/elastic/elasticsearch-java/issues/45
String index = "testindex";
Map<String, Property> fields = Collections.singletonMap("keyword", Property.of(p -> p.keyword(k -> k.ignoreAbove(256))));
Property text = Property.of(p -> p.text(t -> t.fields(fields)));
client.indices().create(c -> c.index(index).mappings(m -> m.properties("id", text).properties("name", p -> p.object(o -> o.properties("first", text).properties("last", text)))));
GetMappingResponse mr = client.indices().getMapping(mrb -> mrb.index(index));
assertNotNull(mr.result().get(index));
assertNotNull(mr.result().get(index).mappings().properties().get("name").object());
}
use of co.elastic.clients.elasticsearch._types.mapping.Property in project opensearch-java by opensearch-project.
the class VariantsTest method testInternalTag.
@Test
public void testInternalTag() {
String expected = "{\"type\":\"ip\",\"fields\":{\"a-field\":{\"type\":\"float\",\"coerce\":true}},\"boost\":1" + ".0,\"index\":true}";
Property p = Property.of(_0 -> _0.ip(_1 -> _1.index(true).boost(1.0).fields("a-field", _3 -> _3.float_(_4 -> _4.coerce(true)))));
assertEquals(expected, toJson(p));
Property property = fromJson(expected, Property.class);
assertTrue(property.ip().index());
assertEquals(1.0, property.ip().boost().doubleValue(), 0.09);
assertTrue(property.ip().fields().get("a-field").float_().coerce());
}
use of co.elastic.clients.elasticsearch._types.mapping.Property in project opensearch-java by opensearch-project.
the class RequestTest method testGetMapping.
@Test
public void testGetMapping() throws Exception {
// See also VariantsTest.testNestedTaggedUnionWithDefaultTag()
String index = "testindex";
Map<String, Property> fields = Collections.singletonMap("keyword", Property.of(p -> p.keyword(k -> k.ignoreAbove(256))));
Property text = Property.of(p -> p.text(t -> t.fields(fields)));
highLevelClient().indices().create(c -> c.index(index).mappings(m -> m.properties("id", text).properties("name", p -> p.object(o -> o.properties("first", text).properties("last", text)))));
GetMappingResponse mr = highLevelClient().indices().getMapping(mrb -> mrb.index(index));
assertNotNull(mr.result().get(index));
assertNotNull(mr.result().get(index).mappings().properties().get("name").object());
}
Aggregations