use of org.elasticsearch.client.indices.GetFieldMappingsResponse in project ARLAS-server by gisaia.
the class ElasticTool method isDateField.
public static boolean isDateField(String field, ElasticClient client, String index) throws ArlasException {
GetFieldMappingsResponse response = client.getFieldMapping(index, field);
String lastKey = field.substring(field.lastIndexOf(".") + 1);
return response.mappings().keySet().stream().anyMatch(indexName -> {
GetFieldMappingsResponse.FieldMappingMetadata data = response.fieldMappings(indexName, field);
boolean isFieldMetadaAMap = (data != null && data.sourceAsMap().get(lastKey) instanceof Map);
if (isFieldMetadaAMap) {
return Optional.of(((Map) data.sourceAsMap().get(lastKey))).map(m -> m.get(ES_TYPE)).map(Object::toString).filter(t -> t.equals(ES_DATE_TYPE)).isPresent();
} else {
// TODO : check if there is another way to fetch field type in this case
return false;
}
});
}
use of org.elasticsearch.client.indices.GetFieldMappingsResponse in project jackrabbit-oak by apache.
the class ElasticSimilarQueryTest method vectorSimilarityElastiknnIndexConfiguration.
@Test
public void vectorSimilarityElastiknnIndexConfiguration() throws Exception {
final String indexName = "test1";
final String fieldName1 = "fv1";
final String similarityFieldName1 = FieldNames.createSimilarityFieldName(fieldName1);
IndexDefinitionBuilder builder = createIndex(fieldName1);
Tree tree = builder.indexRule("nt:base").property(fieldName1).useInSimilarity(true).nodeScopeIndex().similaritySearchDenseVectorSize(2048).getBuilderTree();
tree.setProperty(ElasticPropertyDefinition.PROP_INDEX_SIMILARITY, "cosine");
tree.setProperty(ElasticPropertyDefinition.PROP_NUMBER_OF_HASH_TABLES, 10);
tree.setProperty(ElasticPropertyDefinition.PROP_NUMBER_OF_HASH_FUNCTIONS, 12);
setIndex(indexName, builder);
root.commit();
String alias = ElasticIndexNameHelper.getElasticSafeIndexName(esConnection.getIndexPrefix(), "/oak:index/" + indexName);
GetFieldMappingsRequest fieldMappingsRequest = new GetFieldMappingsRequest();
fieldMappingsRequest.indices(alias).fields(similarityFieldName1);
GetFieldMappingsResponse mappingsResponse = esConnection.getClient().indices().getFieldMapping(fieldMappingsRequest, RequestOptions.DEFAULT);
final Map<String, Map<String, GetFieldMappingsResponse.FieldMappingMetadata>> mappings = mappingsResponse.mappings();
assertEquals("More than one index found", 1, mappings.keySet().size());
@SuppressWarnings("unchecked") Map<String, Object> map1 = (Map<String, Object>) (((Map<String, Object>) mappings.entrySet().iterator().next().getValue().get(similarityFieldName1).sourceAsMap().get(similarityFieldName1)).get("elastiknn"));
assertEquals("Dense vector size doesn't match", 2048, (int) map1.get("dims"));
assertEquals("Similarity doesn't match", "cosine", map1.get("similarity"));
assertEquals("Similarity doesn't match", 10, map1.get("L"));
assertEquals("Similarity doesn't match", 12, map1.get("k"));
}
Aggregations