Created
June 29, 2011 11:09
-
-
Save butlermh/1053654 to your computer and use it in GitHub Desktop.
Test that checks ElasticSearch JSON queries are valid
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.elasticsearchtest; | |
import static org.elasticsearch.common.io.Streams.copyToStringFromClasspath; | |
import java.io.IOException; | |
import org.apache.lucene.search.Query; | |
import org.elasticsearch.common.inject.Injector; | |
import org.elasticsearch.common.inject.ModulesBuilder; | |
import org.elasticsearch.common.settings.ImmutableSettings; | |
import org.elasticsearch.common.settings.Settings; | |
import org.elasticsearch.common.settings.SettingsModule; | |
import org.elasticsearch.index.Index; | |
import org.elasticsearch.index.IndexNameModule; | |
import org.elasticsearch.index.analysis.AnalysisModule; | |
import org.elasticsearch.index.cache.IndexCacheModule; | |
import org.elasticsearch.index.engine.IndexEngineModule; | |
import org.elasticsearch.index.mapper.MapperServiceModule; | |
import org.elasticsearch.index.query.IndexQueryParserModule; | |
import org.elasticsearch.index.query.IndexQueryParserService; | |
import org.elasticsearch.index.settings.IndexSettingsModule; | |
import org.elasticsearch.index.similarity.SimilarityModule; | |
import org.elasticsearch.indices.query.IndicesQueriesModule; | |
import org.elasticsearch.script.ScriptModule; | |
import org.elasticsearch.threadpool.ThreadPoolModule; | |
import org.junit.Before; | |
import org.junit.Test; | |
public class QueryParserTest { | |
// copied code from | |
// org.elasticsearch.index.query.SimpleIndexQueryParserTests | |
// because of visibility issues | |
// some changes to run as JUnit | |
private IndexQueryParserService queryParser; | |
@Before public void setupQueryParser() throws IOException { | |
Settings settings = ImmutableSettings.settingsBuilder() | |
.put("index.cache.filter.type", "none") | |
.build(); | |
Index index = new Index("test"); | |
Injector injector = new ModulesBuilder().add( | |
new SettingsModule(settings), | |
new ThreadPoolModule(settings), | |
new IndicesQueriesModule(), | |
new ScriptModule(settings), | |
new MapperServiceModule(), | |
new IndexSettingsModule(index, settings), | |
new IndexCacheModule(settings), | |
new AnalysisModule(settings), | |
new IndexEngineModule(settings), | |
new SimilarityModule(settings), | |
new IndexQueryParserModule(settings), | |
new IndexNameModule(index) | |
).createInjector(); | |
this.queryParser = injector.getInstance(IndexQueryParserService.class); | |
} | |
private IndexQueryParserService queryParser() throws IOException { | |
return this.queryParser; | |
} | |
@Test public void testNestedBoolean() throws Exception { | |
IndexQueryParserService queryParser = queryParser(); | |
String query = copyToStringFromClasspath("/org/elasticsearchtest/boolquery.json"); | |
Query parsedQuery = queryParser.parse(query).query(); | |
System.out.println(parsedQuery.toString()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment