0

Elk-Stack Version: 8.7.1 Java Api Client: 8.13.1

When executing a search I want to search over all indices excluding all indices that start with a dot. According to the regular Elasticsearch Api you put *,-.* in the path.

When I use the withJson functionality of the Java Api Client I dont have the possibility to define the path with indices, I have just the index-Method.

So how can I exclude these indices ?

Reader queryJson = new StringReader("{\n" +
                    "  \"_source\": {\n" +
                    "    \"excludes\": [ \"@timestamp\", \"@version\" ]\n" +
                    "  },\n" +
                    "  \"size\": 500,\n" +
                    "  \"query\": {\n" +
                    "    \"multi_match\": {\n" +
                    "      \"query\": \"Beratung\",\n" +
                    "      \"fields\": [\"*\"]\n" +
                    "    }\n" +
                    "  }\n" +
                    "}");

            SearchRequest request = SearchRequest.of(b -> b.withJson(queryJson).index("_all"));
            SearchResponse<Object> response = esClient.search(request, Object.class);

I tried passing "", "-." to the index method without success.

1 Answer 1

0

The method you tried GET *,-.*/_search is make sense. If it's not working you can use elasticsearch alias to search all indices at once. Add the alias to all indices you prefer to search.

Note: If your application create daily/monthly indices you can automate this process by adding alias into the index templates.

#add alias to some index pattern or all of them one by one
POST _aliases
{
  "actions": [
    {
      "add": {
        "index": "test-*",
        "alias": "all_indices"
      }
    }
  ]
}

#check if it's added
GET _cat/indices/all_indices?v

#search with alias!
GET all_indices/_search

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.