mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-24 22:09:24 +00:00
Query DSL: ids filter/parse to automatically use types provided as part of the search, closes #1188.
This commit is contained in:
parent
c25d9a7842
commit
2afe7f80a1
@ -25,9 +25,11 @@ import org.elasticsearch.common.collect.Iterables;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.index.search.UidFilter;
|
||||
import org.elasticsearch.search.internal.SearchContext;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
@ -86,7 +88,12 @@ public class IdsFilterParser implements FilterParser {
|
||||
}
|
||||
|
||||
if (types == null || types.isEmpty()) {
|
||||
types = parseContext.mapperService().types();
|
||||
SearchContext searchContext = SearchContext.current();
|
||||
if (searchContext.hasTypes()) {
|
||||
types = Arrays.asList(searchContext.types());
|
||||
} else {
|
||||
types = parseContext.mapperService().types();
|
||||
}
|
||||
} else if (types.size() == 1 && Iterables.getFirst(types, null).equals("_all")) {
|
||||
types = parseContext.mapperService().types();
|
||||
}
|
||||
|
@ -26,9 +26,11 @@ import org.elasticsearch.common.collect.Iterables;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.index.search.UidFilter;
|
||||
import org.elasticsearch.search.internal.SearchContext;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
@ -90,7 +92,12 @@ public class IdsQueryParser implements QueryParser {
|
||||
}
|
||||
|
||||
if (types == null || types.isEmpty()) {
|
||||
types = parseContext.mapperService().types();
|
||||
SearchContext searchContext = SearchContext.current();
|
||||
if (searchContext.hasTypes()) {
|
||||
types = Arrays.asList(searchContext.types());
|
||||
} else {
|
||||
types = parseContext.mapperService().types();
|
||||
}
|
||||
} else if (types.size() == 1 && Iterables.getFirst(types, null).equals("_all")) {
|
||||
types = parseContext.mapperService().types();
|
||||
}
|
||||
|
@ -209,6 +209,10 @@ public class SearchContext implements Releasable {
|
||||
return this.numberOfShards;
|
||||
}
|
||||
|
||||
public boolean hasTypes() {
|
||||
return types != null && types.length > 0;
|
||||
}
|
||||
|
||||
public String[] types() {
|
||||
return types;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user