Merge pull request #11586 from rjernst/fix/field-names-null
Mappings: Shortcut exists and missing queries when no types/docs exist
This commit is contained in:
commit
d372bf7d7a
|
@ -79,6 +79,10 @@ public class ExistsQueryParser implements QueryParser {
|
||||||
|
|
||||||
public static Query newFilter(QueryParseContext parseContext, String fieldPattern, String queryName) {
|
public static Query newFilter(QueryParseContext parseContext, String fieldPattern, String queryName) {
|
||||||
final FieldNamesFieldMapper.FieldNamesFieldType fieldNamesFieldType = (FieldNamesFieldMapper.FieldNamesFieldType)parseContext.mapperService().fullName(FieldNamesFieldMapper.NAME);
|
final FieldNamesFieldMapper.FieldNamesFieldType fieldNamesFieldType = (FieldNamesFieldMapper.FieldNamesFieldType)parseContext.mapperService().fullName(FieldNamesFieldMapper.NAME);
|
||||||
|
if (fieldNamesFieldType == null) {
|
||||||
|
// can only happen when no types exist, so no docs exist either
|
||||||
|
return Queries.newMatchNoDocsQuery();
|
||||||
|
}
|
||||||
|
|
||||||
MapperService.SmartNameObjectMapper smartNameObjectMapper = parseContext.smartObjectMapper(fieldPattern);
|
MapperService.SmartNameObjectMapper smartNameObjectMapper = parseContext.smartObjectMapper(fieldPattern);
|
||||||
if (smartNameObjectMapper != null && smartNameObjectMapper.hasMapper()) {
|
if (smartNameObjectMapper != null && smartNameObjectMapper.hasMapper()) {
|
||||||
|
|
|
@ -91,6 +91,11 @@ public class MissingQueryParser implements QueryParser {
|
||||||
}
|
}
|
||||||
|
|
||||||
final FieldNamesFieldMapper.FieldNamesFieldType fieldNamesFieldType = (FieldNamesFieldMapper.FieldNamesFieldType)parseContext.mapperService().fullName(FieldNamesFieldMapper.NAME);
|
final FieldNamesFieldMapper.FieldNamesFieldType fieldNamesFieldType = (FieldNamesFieldMapper.FieldNamesFieldType)parseContext.mapperService().fullName(FieldNamesFieldMapper.NAME);
|
||||||
|
if (fieldNamesFieldType == null) {
|
||||||
|
// can only happen when no types exist, so no docs exist either
|
||||||
|
return Queries.newMatchNoDocsQuery();
|
||||||
|
}
|
||||||
|
|
||||||
MapperService.SmartNameObjectMapper smartNameObjectMapper = parseContext.smartObjectMapper(fieldPattern);
|
MapperService.SmartNameObjectMapper smartNameObjectMapper = parseContext.smartObjectMapper(fieldPattern);
|
||||||
if (smartNameObjectMapper != null && smartNameObjectMapper.hasMapper()) {
|
if (smartNameObjectMapper != null && smartNameObjectMapper.hasMapper()) {
|
||||||
// automatic make the object mapper pattern
|
// automatic make the object mapper pattern
|
||||||
|
|
|
@ -45,6 +45,16 @@ import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSear
|
||||||
|
|
||||||
public class ExistsMissingTests extends ElasticsearchIntegrationTest {
|
public class ExistsMissingTests extends ElasticsearchIntegrationTest {
|
||||||
|
|
||||||
|
// TODO: move this to a unit test somewhere...
|
||||||
|
public void testEmptyIndex() throws Exception {
|
||||||
|
createIndex("test");
|
||||||
|
ensureYellow("test");
|
||||||
|
SearchResponse resp = client().prepareSearch("test").setQuery(QueryBuilders.existsQuery("foo")).execute().actionGet();
|
||||||
|
assertSearchResponse(resp);
|
||||||
|
resp = client().prepareSearch("test").setQuery(QueryBuilders.missingQuery("foo")).execute().actionGet();
|
||||||
|
assertSearchResponse(resp);
|
||||||
|
}
|
||||||
|
|
||||||
public void testExistsMissing() throws Exception {
|
public void testExistsMissing() throws Exception {
|
||||||
XContentBuilder mapping = XContentBuilder.builder(JsonXContent.jsonXContent)
|
XContentBuilder mapping = XContentBuilder.builder(JsonXContent.jsonXContent)
|
||||||
.startObject()
|
.startObject()
|
||||||
|
|
Loading…
Reference in New Issue