Robin Rieger
Robin Rieger

Reputation: 1194

Elasticsearch 2.1 - Deprecated search types

According to this link, both scan and count are deprecated.

I am trying to change my queries to reflect this. So the count change is easy, just removing the search type and adding size=0 to the request, however, I am not 100% on the scan change.

Currently I have this query:

var result = ElasticClient.Search<Product>(s => s
    .From(0)
    .Size(10)
    .SearchType(SearchType.Scan)
    .Scroll("4s")
    .Query
        (qu =>
            qu.Filtered
                (fil =>
                    fil.Filter
                        (f =>
                            f.Bool(b => b.Must(m => m.Term("filedName", "abc")))))));

Am I correct in my understanding that all I need to change is remove the searchtype and add a sort? I.e:

var result = ElasticClient.Search<Product>(s => s
    .From(0)
    .Size(10)
    .Scroll("4s")
    .Sort(x => x.OnField("_doc"))
    .Query
        (qu =>
            qu.Filtered
                (fil =>
                    fil.Filter
                        (f => f.Bool(b => b.Must(m => m.Term("filedName", "abc")))))));

I have seen a enum SortSpecialField here, but I am not sure how to actually use this in the sort parameter.

Upvotes: 6

Views: 1258

Answers (1)

Dusty
Dusty

Reputation: 3971

You're correct in your understanding that the change (as you document in your question) to sort by _doc will replace the deprecated Scan searchtype. The SortSpecialField enum is just syntax sugar for sorting by _doc. If you prefer to use it, in NEST 2.0 [only], you can do this:

ElasticClient.Search<Product>(s => s
.From(0)
.Size(10)
.Scroll("4s")
.Sort(x => x.Ascending(SortSpecialField.DocumentIndexOrder))
    ...

Upvotes: 6

Related Questions