Search in sources :

Example 1 with GetFieldMappingsRequest

use of org.elasticsearch.client.indices.GetFieldMappingsRequest in project LinkAgent by shulieTech.

the class GetFieldMappingsRequestIndexRename method reindex0.

@Override
public List<String> reindex0(Object target) {
    GetFieldMappingsRequest req = (GetFieldMappingsRequest) target;
    String[] indexes = req.indices();
    for (int i = 0, len = indexes.length; i < len; i++) {
        String index = indexes[i];
        /**
         * 如果在白名单中则不允许写
         */
        if (GlobalConfig.getInstance().getSearchWhiteList().contains(index)) {
            continue;
        }
        if (!Pradar.isClusterTestPrefix(index)) {
            index = Pradar.addClusterTestPrefixLower(index);
            indexes[i] = index;
        }
    }
    req.indices(indexes);
    return Arrays.asList(indexes);
}
Also used : GetFieldMappingsRequest(org.elasticsearch.client.indices.GetFieldMappingsRequest)

Example 2 with GetFieldMappingsRequest

use of org.elasticsearch.client.indices.GetFieldMappingsRequest in project spring-data-elasticsearch by spring-projects.

the class RequestConverters method getFieldMapping.

public static Request getFieldMapping(GetFieldMappingsRequest getFieldMappingsRequest) {
    String[] indices = getFieldMappingsRequest.indices() == null ? Strings.EMPTY_ARRAY : getFieldMappingsRequest.indices();
    String[] fields = getFieldMappingsRequest.fields() == null ? Strings.EMPTY_ARRAY : getFieldMappingsRequest.fields();
    final String endpoint = new EndpointBuilder().addCommaSeparatedPathParts(indices).addPathPartAsIs("_mapping").addPathPartAsIs("field").addCommaSeparatedPathParts(fields).build();
    Request request = new Request(HttpMethod.GET.name(), endpoint);
    RequestConverters.Params parameters = new Params(request);
    parameters.withIndicesOptions(getFieldMappingsRequest.indicesOptions());
    parameters.withIncludeDefaults(getFieldMappingsRequest.includeDefaults());
    return request;
}
Also used : ExplainRequest(org.elasticsearch.action.explain.ExplainRequest) GetMappingsRequest(org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest) SearchTemplateRequest(org.elasticsearch.script.mustache.SearchTemplateRequest) DeleteRequest(org.elasticsearch.action.delete.DeleteRequest) IndexRequest(org.elasticsearch.action.index.IndexRequest) DeleteByQueryRequest(org.elasticsearch.index.reindex.DeleteByQueryRequest) FieldCapabilitiesRequest(org.elasticsearch.action.fieldcaps.FieldCapabilitiesRequest) CountRequest(org.elasticsearch.client.core.CountRequest) IndexTemplatesExistRequest(org.elasticsearch.client.indices.IndexTemplatesExistRequest) GetStoredScriptRequest(org.elasticsearch.action.admin.cluster.storedscripts.GetStoredScriptRequest) GetRequest(org.elasticsearch.action.get.GetRequest) RankEvalRequest(org.elasticsearch.index.rankeval.RankEvalRequest) GetAliasesRequest(org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest) IndicesAliasesRequest(org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest) AbstractBulkByScrollRequest(org.elasticsearch.index.reindex.AbstractBulkByScrollRequest) DeleteIndexTemplateRequest(org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateRequest) ClusterHealthRequest(org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest) GetSettingsRequest(org.elasticsearch.action.admin.indices.settings.get.GetSettingsRequest) PutStoredScriptRequest(org.elasticsearch.action.admin.cluster.storedscripts.PutStoredScriptRequest) ClearScrollRequest(org.elasticsearch.action.search.ClearScrollRequest) PutIndexTemplateRequest(org.elasticsearch.client.indices.PutIndexTemplateRequest) DeleteStoredScriptRequest(org.elasticsearch.action.admin.cluster.storedscripts.DeleteStoredScriptRequest) MultiGetRequest(org.elasticsearch.action.get.MultiGetRequest) SearchRequest(org.elasticsearch.action.search.SearchRequest) OpenIndexRequest(org.elasticsearch.action.admin.indices.open.OpenIndexRequest) MultiSearchRequest(org.elasticsearch.action.search.MultiSearchRequest) CreateIndexRequest(org.elasticsearch.action.admin.indices.create.CreateIndexRequest) RefreshRequest(org.elasticsearch.action.admin.indices.refresh.RefreshRequest) UpdateByQueryRequest(org.elasticsearch.index.reindex.UpdateByQueryRequest) DeleteIndexRequest(org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest) GetIndexRequest(org.elasticsearch.action.admin.indices.get.GetIndexRequest) GetIndexTemplatesRequest(org.elasticsearch.client.indices.GetIndexTemplatesRequest) GetFieldMappingsRequest(org.elasticsearch.client.indices.GetFieldMappingsRequest) UpdateRequest(org.elasticsearch.action.update.UpdateRequest) DocWriteRequest(org.elasticsearch.action.DocWriteRequest) Request(org.elasticsearch.client.Request) AnalyzeRequest(org.elasticsearch.client.indices.AnalyzeRequest) CloseIndexRequest(org.elasticsearch.action.admin.indices.close.CloseIndexRequest) RethrottleRequest(org.elasticsearch.client.RethrottleRequest) FlushRequest(org.elasticsearch.action.admin.indices.flush.FlushRequest) PutMappingRequest(org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest) SearchScrollRequest(org.elasticsearch.action.search.SearchScrollRequest) BulkRequest(org.elasticsearch.action.bulk.BulkRequest) ReindexRequest(org.elasticsearch.index.reindex.ReindexRequest)

Example 3 with GetFieldMappingsRequest

use of org.elasticsearch.client.indices.GetFieldMappingsRequest 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"));
}
Also used : IndexDefinitionBuilder(org.apache.jackrabbit.oak.plugins.index.search.util.IndexDefinitionBuilder) Tree(org.apache.jackrabbit.oak.api.Tree) GetFieldMappingsRequest(org.elasticsearch.client.indices.GetFieldMappingsRequest) GetFieldMappingsResponse(org.elasticsearch.client.indices.GetFieldMappingsResponse) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 4 with GetFieldMappingsRequest

use of org.elasticsearch.client.indices.GetFieldMappingsRequest in project SOS by 52North.

the class SosElasticsearchSchemasTest method createSchema.

@Test
@Ignore
public void createSchema() throws IOException {
    SosElasticsearchSchemas sch = new SosElasticsearchSchemas();
    Map<String, Object> map = new HashMap<>();
    map.put(type, sch.getSchema());
    getEmbeddedClient().indices().create(new CreateIndexRequest(idx).mapping(map), RequestOptions.DEFAULT);
    GetFieldMappingsResponse resp = getEmbeddedClient().indices().getFieldMapping(new GetFieldMappingsRequest().indices(idx).fields(type), RequestOptions.DEFAULT);
    Assert.assertNotNull(resp.mappings());
}
Also used : HashMap(java.util.HashMap) GetFieldMappingsRequest(org.elasticsearch.client.indices.GetFieldMappingsRequest) CreateIndexRequest(org.elasticsearch.client.indices.CreateIndexRequest) GetFieldMappingsResponse(org.elasticsearch.client.indices.GetFieldMappingsResponse) Ignore(org.junit.Ignore) Test(org.junit.Test) ElasticsearchAwareTest(basetest.ElasticsearchAwareTest)

Example 5 with GetFieldMappingsRequest

use of org.elasticsearch.client.indices.GetFieldMappingsRequest in project SOS by 52North.

the class SosElasticsearchSchemasTest method createMetaDataSchema.

@Test
@Ignore
public void createMetaDataSchema() throws IOException {
    SosElasticsearchSchemas sch = new SosElasticsearchSchemas();
    Map<String, Object> map = new HashMap<>();
    map.put(type, sch.getMetadataSchema());
    getEmbeddedClient().indices().create(new CreateIndexRequest(idx).mapping(map), RequestOptions.DEFAULT);
    GetFieldMappingsResponse resp = getEmbeddedClient().indices().getFieldMapping(new GetFieldMappingsRequest().indices(idx).fields(type), RequestOptions.DEFAULT);
    Assert.assertNotNull(resp.mappings());
}
Also used : HashMap(java.util.HashMap) GetFieldMappingsRequest(org.elasticsearch.client.indices.GetFieldMappingsRequest) CreateIndexRequest(org.elasticsearch.client.indices.CreateIndexRequest) GetFieldMappingsResponse(org.elasticsearch.client.indices.GetFieldMappingsResponse) Ignore(org.junit.Ignore) Test(org.junit.Test) ElasticsearchAwareTest(basetest.ElasticsearchAwareTest)

Aggregations

GetFieldMappingsRequest (org.elasticsearch.client.indices.GetFieldMappingsRequest)5 HashMap (java.util.HashMap)3 GetFieldMappingsResponse (org.elasticsearch.client.indices.GetFieldMappingsResponse)3 Test (org.junit.Test)3 ElasticsearchAwareTest (basetest.ElasticsearchAwareTest)2 CreateIndexRequest (org.elasticsearch.client.indices.CreateIndexRequest)2 Ignore (org.junit.Ignore)2 Map (java.util.Map)1 Tree (org.apache.jackrabbit.oak.api.Tree)1 IndexDefinitionBuilder (org.apache.jackrabbit.oak.plugins.index.search.util.IndexDefinitionBuilder)1 DocWriteRequest (org.elasticsearch.action.DocWriteRequest)1 ClusterHealthRequest (org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest)1 DeleteStoredScriptRequest (org.elasticsearch.action.admin.cluster.storedscripts.DeleteStoredScriptRequest)1 GetStoredScriptRequest (org.elasticsearch.action.admin.cluster.storedscripts.GetStoredScriptRequest)1 PutStoredScriptRequest (org.elasticsearch.action.admin.cluster.storedscripts.PutStoredScriptRequest)1 IndicesAliasesRequest (org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest)1 GetAliasesRequest (org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest)1 CloseIndexRequest (org.elasticsearch.action.admin.indices.close.CloseIndexRequest)1 CreateIndexRequest (org.elasticsearch.action.admin.indices.create.CreateIndexRequest)1 DeleteIndexRequest (org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest)1