# Issue with reindexing

**URL:** <https://discuss.elastic.co/t/issue-with-reindexing/17847>\
**Category:** Elasticsearch\
**Created:** [June 1, 2014, 2:49pm UTC](https://discuss.elastic.co/t/issue-with-reindexing/17847 "2014-06-01T14:49:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Niv\_Penso](https://avatars.discourse-cdn.com/v4/letter/n/b487fb/32.png) [@Niv\_Penso](https://discuss.elastic.co/u/Niv_Penso)\
**Post date:** [June 1, 2014, 2:49pm UTC](https://discuss.elastic.co/t/issue-with-reindexing/17847/1 "2014-06-01T14:49:39Z")

</div>

Hey guys,

I am using the script below to reindex 115,000 documents. (I am running the  
script locally)

\<?php // PHP ReIndexer with Bulk API require 'vendor/autoload.php'; // we use this function to create the "scan & scroll" search requests because such requests doesn't exist in the ES PHP API. function curlWrapper($uri, $method, $data = '') { $ch = curl\_init($uri); curl\_setopt($ch, CURLOPT\_RETURNTRANSFER, true); curl\_setopt($ch, CURLOPT\_CUSTOMREQUEST, $method); curl\_setopt($ch, CURLOPT\_HTTP\_VERSION, CURL\_HTTP\_VERSION\_1\_0); if ($data != '') curl\_setopt($ch, CURLOPT\_POSTFIELDS, $data); $response = curl\_exec($ch); curl\_close($ch); return $response; } error\_reporting(E\_ALL); ini\_set( 'display\_errors','1'); date\_default\_timezone\_set("UTC"); $ELSEARCH\_SERVER = "http://someserver:9200/"; $OLDINDEX = "OldIndex"; //old index $SECONDINDEX = "NewIndex"; // new index $TYPE = 'MyType'; // old type $LOGPATH = '/var/log/elasticsearch/elasticsearch.log'; $clientParams = array(); $clientParams['logging'] = true; $clientParams['logPath'] = $LOGPATH; $clientParams['logLevel'] = Psr\Log\LogLevel::INFO; $clientParams['hosts'] = array ($ELSEARCH\_SERVER); $dstEl = new Elasticsearch\Client($clientParams); //start the scan request //We want to find all documents, so we do a simple match\_all $query ='{"query" : {"match\_all" : {}}}'; //The scroll=10m param says that this scroll session should be valid for 10 minutes before expiring //The size=100 param says that 100 results should be returned per scroll $uri = $ELSEARCH\_SERVER.$OLDINDEX."/".$TYPE. "/\_search?search\_type=scan&scroll=10m&size=100"; $response = curlWrapper($uri, 'GET', $query); $data = json\_decode($response); //total number of documents in the index $total = $data-\>hits-\>total; //scroll session id, used to request the next batch of data $scroll\_id = $data-\>\_scroll\_id; //The scan request doesn't actually return any data, just a session "scroll id" //We now query ES and provide this id to start retrieving the data $uri = $ELSEARCH\_SERVER."\_search/scroll?scroll=10m"; $response = curlWrapper($uri, 'GET', $scroll\_id); $data = json\_decode($response); // Initialize bulk insertion parameters. $bulkInsertParams = array(); $bulkInsertParams['index'] = $SECONDINDEX; $bulkInsertParams['type'] = $TYPE; echo date("Y-m-d H:i:s") . ": Start ReIndexing." . PHP\_EOL; //Loop through all the data while (count($data-\>hits-\>hits) \> 0) { $bulkInsertParams["body"]=null; foreach ($data-\>hits-\>hits as $item) // run for each match of the "scan&scroll search". { $bulkInsertParams["body"][] = array( 'index' =\> array( '\_id' =\> $item-\>\_id ) ); $bulkInsertParams["body"][] = array( 'doc' =\> $item-\>\_source ); } $retVal = $dstEl-\>bulk($bulkInsertParams); //Each scroll request returns another scroll\_id which is used to continue //scrolling through the data $scroll\_id = $data-\>\_scroll\_id; //retrieve the next batch of data - the new session is good for an additional 10m, etc etc $uri = $ELSEARCH\_SERVER."\_search/scroll?scroll=10m"; $response = curlWrapper($uri, 'GET', $scroll\_id); $data = json\_decode($response); } echo date("Y-m-d H:i:s") . ": DONE!" . PHP\_EOL; ?\>

every thing seems to work fine and even when i use this query:

GET NewIndex/MyType/\_search  
{  
"size":0  
}

I get these results (Which looks good)

{  
"took": 2,  
"timed\_out": false,  
"\_shards": {  
"total": 5,  
"successful": 5,  
"failed": 0  
},  
"hits": {  
"total": 115102,  
"max\_score": 0,  
"hits": []  
}  
}

But when i am trying to make a query on the documents' field i get no  
results while when i run the exact same query on the old index i get the  
expected results..

This is the query (if it helps):

GET NewIndex/MyType/\_search  
{  
"query": {  
"terms": {  
"doc\_type": [  
"user\_view"  
]  
}  
}  
}

the results are:

{  
"took": 3,  
"timed\_out": false,  
"\_shards": {  
"total": 5,  
"successful": 5,  
"failed": 0  
},  
"hits": {  
"total": 0,  
"max\_score": 0,  
"hits": []  
}  
}

while the results for the OldIndex are:

{  
"took": 3,  
"timed\_out": false,  
"\_shards": {  
"total": 5,  
"successful": 5,  
"failed": 0  
},  
"hits": {  
"total": 104452,  
"max\_score": 0,  
"hits": []  
}  
}

I am wondering if there is something else that i should do to make the  
documents get indexed in the elasticsearch?

Note:  
(\*) when I try to get specific document (by key) from NewIndex the results  
is fine..

Thnx for you help  
Niv 🙂

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/84795182-eab5-4b74-a8ef-d1bcdb989659%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/84795182-eab5-4b74-a8ef-d1bcdb989659%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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 6, 2017, 1:25am UTC](https://discuss.elastic.co/t/issue-with-reindexing/17847/2 "2017-07-06T01:25:27Z")

</div>


