Hi , I am trying to query with Lucene index but getting the empty result and below errors in the log, Traversal query (query without index): select [jcr:path] from [nt:base] where isdescendantnode('/test') and name='World'; consider creating an index [async] The index update failed org.apache.jackrabbit.oak.api.CommitFailedException: OakAsync0002: Missing index provider detected for type [counter] on index [/oak:index/counter]
can you help me to find what wrong I am doing here, PFA of my code. Regards, Sandeep Ambule
public class SimpleTest { @Test public void simpleTest() throws Exception { NodeStore store = new MemoryNodeStore(); //create reposiotory LuceneIndexProvider provider = new LuceneIndexProvider(); ContentRepository repository = new Oak(store) .with(new OpenSecurityProvider()) .with(new InitialContent()) .with(new NodeCounterEditorProvider()) .with((QueryIndexProvider) provider) .with((Observer) provider) .with(new LuceneIndexEditorProvider()) .withAsyncIndexing("async", 5).createContentRepository(); //login reposiotory and retrive session ContentSession contentSession = repository.login(null, null); Root root = contentSession.getLatestRoot(); //create lucene index IndexDefinitionBuilder idxBuilder = new IndexDefinitionBuilder().async("async"); idxBuilder.indexRule("nt:base").property("name").propertyIndex(); idxBuilder.build(root.getTree("/").addChild("oak:index").addChild("lucene")); root.commit(); //Create TestNode String h = "Hello"; String w = "World"; Tree test = root.getTree("/").addChild("test"); test.addChild("a").setProperty("name", Arrays.asList(new String[] { h, w }), Type.STRINGS); test.addChild("b").setProperty("name", h); root.commit(); // wait for async indexing cycle (avoiding more elegant ways) Thread.sleep(TimeUnit.SECONDS.toMillis(10)); //Search String query = "select [jcr:path] from [nt:base] where isdescendantnode('/test') and name='World' option(traversal fail)"; List<String> paths = executeQuery(root, query); for (String path : paths) { System.out.println("Path=" + path); } } private List<String> executeQuery(Root root, String query) throws ParseException { Result result = root.getQueryEngine() .executeQuery(query, "JCR-SQL2", QueryEngine.NO_BINDINGS, QueryEngine.NO_MAPPINGS); return StreamSupport.stream(result.getRows().spliterator(), false) .map(row -> row.getPath()) .collect(Collectors.toList()); } }