6

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.

5
  • Which version of NEST are you using? Commented Jan 12, 2016 at 22:04
  • From nuget, elasticsearch.net and nest.... both 1.7.1 Commented Jan 12, 2016 at 22:11
  • NEST and Elasticsearch.NET 1.7.1 are not compatible with ES 2.x - they may generally work but there are changes in Elasticsearch that will not e.g. error responses. There is a 2.x alpha pre-release of NEST on nuget Commented Jan 12, 2016 at 22:21
  • hmm yes, here 6 days ago. totally missed it. Hmm ok. My understanding but of the syntax/logic change to the query is correct but right? I mean, I just need to add the 'sort' on the doc field and the query will work the same.... Commented Jan 12, 2016 at 22:32
  • 1
    Yes, the change you have outlined above looks correct Commented Jan 12, 2016 at 22:37

1 Answer 1

6

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))
    ...
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.