add explicit type missing exception when trying to search on a type that is not registered

This commit is contained in:
kimchy 2011-01-14 17:53:45 +02:00
parent a8be99b7e0
commit f8b1d1eebd
3 changed files with 16 additions and 37 deletions

View File

@ -32,11 +32,16 @@ import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.lucene.Lucene;
import org.elasticsearch.common.lucene.uid.UidField;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.engine.Engine;
import org.elasticsearch.index.mapper.*;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.FieldMapper;
import org.elasticsearch.index.mapper.FieldMappers;
import org.elasticsearch.index.mapper.FieldMappersFieldSelector;
import org.elasticsearch.index.service.IndexService;
import org.elasticsearch.index.shard.service.IndexShard;
import org.elasticsearch.indices.IndicesService;
import org.elasticsearch.indices.TypeMissingException;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportService;
@ -79,7 +84,7 @@ public class TransportGetAction extends TransportShardSingleOperationAction<GetR
DocumentMapper docMapper = indexService.mapperService().documentMapper(request.type());
if (docMapper == null) {
throw new DocumentMapperNotFoundException("No mapper found for type [" + request.type() + "]");
throw new TypeMissingException(new Index(request.index()), request.type());
}
if (request.refresh()) {

View File

@ -1,34 +0,0 @@
/*
* Licensed to Elastic Search and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. Elastic Search licenses this
* file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.index.mapper;
/**
* @author kimchy (Shay Banon)
*/
public class DocumentMapperNotFoundException extends MapperException {
public DocumentMapperNotFoundException(String message) {
super(message);
}
public DocumentMapperNotFoundException(String message, Throwable cause) {
super(message, cause);
}
}

View File

@ -41,6 +41,7 @@ import org.elasticsearch.index.analysis.AnalysisService;
import org.elasticsearch.index.mapper.xcontent.XContentDocumentMapperParser;
import org.elasticsearch.index.settings.IndexSettings;
import org.elasticsearch.indices.InvalidTypeNameException;
import org.elasticsearch.indices.TypeMissingException;
import javax.annotation.Nullable;
import java.io.File;
@ -237,10 +238,17 @@ public class MapperService extends AbstractIndexComponent implements Iterable<Do
*/
public Filter typesFilter(String... types) {
if (types.length == 1) {
return documentMapper(types[0]).typeFilter();
DocumentMapper docMapper = documentMapper(types[0]);
if (docMapper == null) {
throw new TypeMissingException(index, types[0]);
}
return docMapper.typeFilter();
}
PublicTermsFilter termsFilter = new PublicTermsFilter();
for (String type : types) {
if (!hasMapping(type)) {
throw new TypeMissingException(index, type);
}
termsFilter.addTerm(new Term(TypeFieldMapper.NAME, type));
}
return termsFilter;