use of org.opensearch.client.opensearch._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 org.opensearch.client.opensearch._types.mapping.Property in project opensearch-java by opensearch-project.
the class VariantsTest method testNestedTaggedUnionWithDefaultTag.
@Test
public void testNestedTaggedUnionWithDefaultTag() {
// Object fields don't really exist in ES and are based on a naming convention where field names
// are dot-separated paths. The hierarchy is rebuilt from these names and ES doesn't send back
// "type": "object" for object properties.
//
// Mappings are therefore a hierarchy of internally-tagged unions based on the "type" property
// with a default "object" tag value if the "type" property is missing.
String json = "{\n" + " \"testindex\" : {\n" + " \"mappings\" : {\n" + " \"properties\" : {\n" + " \"id\" : {\n" + " \"type\" : \"text\",\n" + " \"fields\" : {\n" + " \"keyword\" : {\n" + " \"type\" : \"keyword\",\n" + " \"ignore_above\" : 256\n" + " }\n" + " }\n" + " },\n" + " \"name\" : {\n" + " \"properties\" : {\n" + " \"first\" : {\n" + " \"type\" : \"text\",\n" + " \"fields\" : {\n" + " \"keyword\" : {\n" + " \"type\" : \"keyword\",\n" + " \"ignore_above\" : 256\n" + " }\n" + " }\n" + " },\n" + " \"last\" : {\n" + " \"type\" : \"text\",\n" + " \"fields\" : {\n" + " \"keyword\" : {\n" + " \"type\" : \"keyword\",\n" + " \"ignore_above\" : 256\n" + " }\n" + " }\n" + " }\n" + " }\n" + " }\n" + " }\n" + " }\n" + " }\n" + "}";
GetMappingResponse response = fromJson(json, GetMappingResponse.class);
TypeMapping mappings = response.get("testindex").mappings();
assertTrue(mappings.properties().get("name").isObject());
assertEquals(256, mappings.properties().get("name").object().properties().get("first").text().fields().get("keyword").keyword().ignoreAbove().longValue());
assertTrue(mappings.properties().get("id").isText());
assertEquals(256, mappings.properties().get("id").text().fields().get("keyword").keyword().ignoreAbove().longValue());
}
use of org.opensearch.client.opensearch._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 org.opensearch.client.opensearch._types.mapping.Property in project opensearch-java by opensearch-project.
the class BehaviorsTest method testAdditionalProperties.
@Test
public void testAdditionalProperties() {
// Check that additional property map is initialized even if not set explicitly
ErrorCause err = new ErrorCause.Builder().reason("Foo").type("Bar").build();
assertEquals(0, err.metadata().size());
err = new ErrorCause.Builder().reason("Some failure").type("Some type").metadata(MapBuilder.of("index", JsonData.of("test"), "retries", JsonData.of(1))).build();
err = checkJsonRoundtrip(err, "{\"index\":\"test\",\"retries\":1,\"type\":\"Some type\",\"reason\":\"Some failure\"}");
assertEquals("Some failure", err.reason());
assertEquals(1, err.metadata().get("retries").to(int.class).intValue());
assertEquals("test", err.metadata().get("index").to(String.class));
}
use of org.opensearch.client.opensearch._types.mapping.Property in project opensearch-java by opensearch-project.
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());
}
Aggregations