Skip to content

Commit 54434c3

Browse files
Gabriel MoskoviczGabriel Moskovicz
Gabriel Moskovicz
authored and
Gabriel Moskovicz
committedJun 8, 2015
Added generic and all types to search descriptor
1 parent c501daf commit 54434c3

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed
 

‎src/Nest/Domain/Observers/ReindexObservable.cs

+17-7
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,27 @@ private void Reindex(IObserver<IReindexResponse<T>> observer)
5151
if (!createIndexResponse.IsValid)
5252
throw new ReindexException(createIndexResponse.ConnectionStatus);
5353

54-
var page = 0;
55-
var searchResult = this.CurrentClient.Search<T>(
56-
s => s
57-
.Index(fromIndex)
58-
.AllTypes()
54+
var page = 0;
55+
Func<SearchDescriptor<T>, SearchDescriptor<T>> searchDescriptor = s => s.Index(fromIndex);
56+
57+
if (typeof (T).Name.Equals(typeof (object).Name))
58+
{
59+
searchDescriptor = s => searchDescriptor(s).AllTypes();
60+
}
61+
else
62+
{
63+
searchDescriptor = s => searchDescriptor(s).Type<T>();
64+
}
65+
66+
67+
var searchResult = this.CurrentClient.Search<T>(
68+
s => searchDescriptor(s)
5969
.From(0)
6070
.Size(size)
6171
.Query(this._reindexDescriptor._QuerySelector ?? (q=>q.MatchAll()))
6272
.SearchType(SearchType.Scan)
63-
.Scroll(scroll)
64-
);
73+
.Scroll(scroll));
74+
6575
if (searchResult.Total <= 0)
6676
throw new ReindexException(searchResult.ConnectionStatus, "index " + fromIndex + " has no documents!");
6777
IBulkResponse indexResult = null;

0 commit comments

Comments
 (0)
Please sign in to comment.