# Search in wrong Index

**URL:** <https://discuss.elastic.co/t/search-in-wrong-index/270369>\
**Category:** Elasticsearch\
**Created:** [April 16, 2021, 9:54am UTC](https://discuss.elastic.co/t/search-in-wrong-index/270369 "2021-04-16T09:54:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gioking](https://avatars.discourse-cdn.com/v4/letter/g/c68b51/32.png) [@Gioking](https://discuss.elastic.co/u/Gioking)\
**Post date:** [April 16, 2021, 9:54am UTC](https://discuss.elastic.co/t/search-in-wrong-index/270369/1 "2021-04-16T09:54:53Z")

</div>

Hi all, I'm new to Elasticsearch, I had to add a couple of field in mssql, the same fields must be created in elasticsearch.  
To add new fields I follow this procedure:

1 Copy the index mapping from the original index  
GET sgs\_products/\_mapping

2 Create the new destination index and add the new fields as needed  
PUT sgs\_products\_dest  
{  
"mappings": {  
"properties": {  
"availableTranslations": {  
"type": "text",  
"fields": {  
"keyword": {  
"type": "keyword",  
"ignore\_above": 256  
}  
}  
},  
"barCode": {  
"type": "text",  
"fields": {  
"keyword": {  
"type": "keyword",  
"ignore\_above": 256  
}  
}  
},  
"brandId": {  
"type": "long"  
},  
"brandProductNameId": {  
"type": "long"  
},

```
  Ecc…

```

3 Do the reindex from the original index to the new index  
POST \_reindex  
{  
"source":{  
"index":"sgs\_products"  
},  
"dest":{  
"index":"sgs\_products\_dest"  
}  
}

4 Valorize the new added fields with a default value to all documents  
POST sgs\_products\_dest/\_update\_by\_query  
{  
"script": {  
"source": "ctx.\_source.isNewentry = true",  
"lang": "painless"  
}  
}  
POST sgs\_products\_dest/\_update\_by\_query  
{  
"script": {  
"source": "ctx.\_source.isExclusive = false",  
"lang": "painless"  
}  
}  
POST sgs\_products\_dest/\_update\_by\_query  
{  
"script": {  
"source": "ctx.\_source.isNewEntryFrom = "1999-01-01"",  
"lang": "painless"  
}  
}  
POST sgs\_products\_dest/\_update\_by\_query  
{  
"script": {  
"source": "ctx.\_source.isNewEntryTo = "1999-01-01"",  
"lang": "painless"  
}  
}  
POST sgs\_products\_dest/\_update\_by\_query  
{  
"script": {  
"source": "ctx.\_source.isSpecialOfferFrom = "1999-01-01"",  
"lang": "painless"  
}  
}  
POST sgs\_products\_dest/\_update\_by\_query  
{  
"script": {  
"source": "ctx.\_source.isSpecialOfferTo = "1999-01-01"",  
"lang": "painless"  
}  
}

5 Delete the old index  
DELETE sgs\_products

6 Get the mapping from the new index  
GET sgs\_products\_dest/\_mapping

7 Re-create the original index with the mapping obtained at step 6  
PUT sgs\_products  
{  
"mappings": {  
"properties": {  
"availableTranslations": {  
"type": "text",  
"fields": {  
"keyword": {  
"type": "keyword",  
"ignore\_above": 256  
}  
}  
},  
"barCode": {  
"type": "text",  
"fields": {  
"keyword": {  
"type": "keyword",  
"ignore\_above": 256  
}  
}  
},  
"brandId": {  
"type": "long"  
},  
"brandProductNameId": {  
"type": "long"  
},  
Ecc…

## 8 Do inverse reindex from new index to the original index to have the original index with original name. POST \_reindex { "source":{ "index":"sgs\_products\_dest" }, "dest":{ "index":"sgs\_products" } }

Now when I query Elasticsearch by using Nest library the field isNewentry is always false.

Could some one help me to understand why the isNewentry is false ?

Thank you very much  
Gio

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [April 19, 2021, 11:33pm UTC](https://discuss.elastic.co/t/search-in-wrong-index/270369/2 "2021-04-19T23:33:23Z")

</div>

Welcome to our community! 😃  
Please format your code/logs/config using the `</>` button, or markdown style back ticks. It helps to make things easy to read which helps us help you 🙂

---

<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:** [May 17, 2021, 11:34pm UTC](https://discuss.elastic.co/t/search-in-wrong-index/270369/3 "2021-05-17T23:34:05Z")

</div>

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