# NEST Client - BULK Method - Insert or update or delete

**URL:** https://discuss.elastic.co/t/nest-client-bulk-method-insert-or-update-or-delete/184890
**Category:** Elasticsearch
**Created:** [June 9, 2019, 7:00pm UTC](https://discuss.elastic.co/t/nest-client-bulk-method-insert-or-update-or-delete/184890 "2019-06-09T19:00:14Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![krishnapss](https://avatars.discourse-cdn.com/v4/letter/k/43a26b/32.png) [@krishnapss](https://discuss.elastic.co/u/krishnapss)
#### Post date: [June 9, 2019, 7:00pm UTC](https://discuss.elastic.co/t/nest-client-bulk-method-insert-or-update-or-delete/184890/1 "2019-06-09T19:00:14Z")

</div>

Hi,  
I am trying to use Bulk method using c# NEST client.  
**Example**  
Lets say I have indexed 1000 documents first time.  
Second time I have 800 documents. But I don't know whether these are new or old. I have to replace existing 1000 with these 800.  
When using Bulk method, it is creating new documents if there are no matching ids and updating if any matching documents found.  
My problem is how to delete the 200 unmatched documents.  
There is Delete API but as I have mentioned earlier I don't have the ids which are deleted.  
I could query elastic search to give me the ids other than these 800 ids and then delete it, but I am not sure that's the best way to do this.  
**OR**  
Do you think using Index Aliases feature will solve this problem. If I use Index Aliases I have to delete the old index after pointing to the new index but does this affect the search scoring?  
Could you please help me to solve this problem.

Thanks,  
Krishna

---

<div class="post-metadata">

### Author: ![forloop](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/forloop/32/9021_2.png) [@forloop](https://discuss.elastic.co/u/forloop)
#### Post date: [June 10, 2019, 12:13am UTC](https://discuss.elastic.co/t/nest-client-bulk-method-insert-or-update-or-delete/184890/2 "2019-06-10T00:13:39Z")

</div>

A better approach might be to

1. use an alias and versioned indices e.g. alias `documents` pointing to single index `documents-v1`
2. index 1000 documents into `documents-v1` (using either the index name or alias)
3. index 800 documents into new index `documents-v2`
4. remove index from pointing to `documents-v1` and point it to `documents-v2`
5. delete index `documents-v1`

For 800-1000 documents, a single primary shard can be used (with replicas, for redundancy), so scoring will be based on the entire document corpus in each case.

---

<div class="post-metadata">

### Author: ![krishnapss](https://avatars.discourse-cdn.com/v4/letter/k/43a26b/32.png) [@krishnapss](https://discuss.elastic.co/u/krishnapss)
#### Post date: [June 10, 2019, 8:17am UTC](https://discuss.elastic.co/t/nest-client-bulk-method-insert-or-update-or-delete/184890/3 "2019-06-10T08:17:03Z")

</div>

Thank you very much for replying back.  
Just to be sure please  
**Example**  
From 1000 documents each document has one property called `PropertyA`.  
After indexing and searching for some time the `PropertA` score is 0.9.  
So after indexing second time (800 documents) using this approach, the `PropertyA` score will be 0.9? Is that right please?  
And in future if i have 25000 plus documents does this still be the case please.

Thanks,  
Krishna

---

<div class="post-metadata">

### Author: ![forloop](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/forloop/32/9021_2.png) [@forloop](https://discuss.elastic.co/u/forloop)
#### Post date: [June 10, 2019, 8:34am UTC](https://discuss.elastic.co/t/nest-client-bulk-method-insert-or-update-or-delete/184890/4 "2019-06-10T08:34:31Z")

</div>

> [@krishnapss](#):
>
> From 1000 documents each document has one property called `PropertyA` .  
> After indexing and searching for some time the `PropertA` score is 0.9.  
> So after indexing second time (800 documents) using this approach, the `PropertyA` score will be 0.9? Is that right please?

That is not correct; scores are calculated relative to the document corpus, by default using [BM25](https://www.elastic.co/guide/en/elasticsearch/reference/current/index-modules-similarity.html#bm25). A component of document scoring is the inverse of the frequency of a term within the entire document corpus, so it's highly probable that scores calculated for the 1000 documents will be different than those calculated for the 800 documents.

Take a look at the [practical BM25 blog post series](https://www.elastic.co/blog/practical-bm25-part-1-how-shards-affect-relevance-scoring-in-elasticsearch) to understand more about how scores are calculated.

---

<div class="post-metadata">

### Author: ![krishnapss](https://avatars.discourse-cdn.com/v4/letter/k/43a26b/32.png) [@krishnapss](https://discuss.elastic.co/u/krishnapss)
#### Post date: [June 10, 2019, 8:49am UTC](https://discuss.elastic.co/t/nest-client-bulk-method-insert-or-update-or-delete/184890/5 "2019-06-10T08:49:13Z")

</div>

Yes, of course the score won't be same. My thinking was whether this approach has any affects or not on the original score but as you have mentioned depends on `A component of document scoring is the inverse of the frequency of a term within the entire document corpus`.  
I will read those documents.  
Thank you very much for pointing me in right direction.

---

<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: [July 8, 2019, 8:49am UTC](https://discuss.elastic.co/t/nest-client-bulk-method-insert-or-update-or-delete/184890/6 "2019-07-08T08:49:15Z")

</div>

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