# DeleteByQuery using "from"

**URL:** https://discuss.elastic.co/t/deletebyquery-using-from/251135
**Category:** Elasticsearch
**Tags:** language-clients
**Created:** [October 6, 2020, 1:29pm UTC](https://discuss.elastic.co/t/deletebyquery-using-from/251135 "2020-10-06T13:29:10Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Alder](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alder/32/58170_2.png) [@Alder](https://discuss.elastic.co/u/Alder)
#### Post date: [October 6, 2020, 1:29pm UTC](https://discuss.elastic.co/t/deletebyquery-using-from/251135/1 "2020-10-06T13:29:10Z")

</div>

Hello everyone from elastic

I try to exclude some docs by specifying the starting document offset.

Based on the documentation below

> **[Delete by query API | Elasticsearch Reference \[7.8\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/7.8/docs-delete-by-query.html)**

I write this C # code

```auto
public async Task EraseData(string indexName, int from, int pageLength)
        {
            var response = this.AnalysisRepository.Client.DeleteByQuery<Dictionary<string, object>>(del => del
                                .Index(indexName)
                                .MaximumDocuments(pageLength)
                                .From(from)
                                .Query(q => q
                                    .QueryString(qs => qs
                                        .Query("*")
                                        )
                                    )
                                );
        }

```

But I get this error:  
Validation Failed: 1: from is not supported in this contex

Elastic version 7.8.1  
Nest version 7.8.1

---

<div class="post-metadata">

### Author: ![Alder](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alder/32/58170_2.png) [@Alder](https://discuss.elastic.co/u/Alder)
#### Post date: [October 19, 2020, 11:13am UTC](https://discuss.elastic.co/t/deletebyquery-using-from/251135/2 "2020-10-19T11:13:30Z")

</div>

Hi all from elastic, I find one solution with DeleteMany

```auto
// 01 buscar os documentos sem os campos de auto descoberta
                var observer = this.AnalysisRepository.Client.ScrollAll<Dictionary<string, object>>("50m", 3, sc => sc
                                                        .MaxDegreeOfParallelism(4)
                                                        .Search(s => s
                                                            .Index(analysis.IndexName)
                                                            .Size(1000)
                                                            .Source(sf => sf
                                                                .Excludes(e => e.Fields("d.*", "n.*")) // <- Exclui os campos de auto descoberta e NER
                                                             )
                                                            .MatchAll()
                                                        )
                                                     );

                var waitHandle = new ManualResetEvent(false);

                Exception ex = null;

                observer.Subscribe(new ScrollAllObserver<Dictionary<string, object>>(
                            onNext: r =>
                            {
                                // 02 aplicar dicionario de verbetes
                                var itens = this.dictionaryService.ApplyDictionary(r.SearchResponse.Documents.ToList<Dictionary<string, object>>(), masks, analysis);

                                // 03 limpa o indice antes de inserir os itens com as atualizações da auto descoberta
                                var response = this.AnalysisRepository.Client.DeleteMany(r.SearchResponse.Hits, model.IndexName);

                                // 04 gravar itens atualizados
                                Exception ex = this.elasticService.AddItensElastic(itens, model.IndexName, boolNer, analysis);

                                if (ex != null)
                                {
                                    throw new Exception("Erro ao realizar atualização da análise!", ex);
                                }
                            },
                            onError: e =>
                            {
                                ex = e;
                                waitHandle.Set();
                            },
                            onCompleted: () =>
                            {
                                waitHandle.Set();
                            }
                        )
                    );

                waitHandle.WaitOne(TimeSpan.FromMinutes(20));

```

---

<div class="post-metadata">

### Author: ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)
#### Post date: [October 19, 2020, 11:16am UTC](https://discuss.elastic.co/t/deletebyquery-using-from/251135/3 "2020-10-19T11:16:46Z")

</div>

can you explain what you are trying to achieve with a from, when you want to delete documents based on a query criteria? I do not understand the use-case and I have the feeling that this may lead to a wrong solution.

---

<div class="post-metadata">

### Author: ![Alder](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alder/32/58170_2.png) [@Alder](https://discuss.elastic.co/u/Alder)
#### Post date: [October 19, 2020, 11:35am UTC](https://discuss.elastic.co/t/deletebyquery-using-from/251135/4 "2020-10-19T11:35:32Z")

</div>

My objective is reindex an index, in small blocks, applying the ApplyDictionary() method.  
To update the index I delete the old items and include the new itens by applying the ApplyDictionary() method.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [November 16, 2020, 11:35am UTC](https://discuss.elastic.co/t/deletebyquery-using-from/251135/5 "2020-11-16T11:35:49Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
