# Real-time vs. Near real-time searching

**URL:** <https://discuss.elastic.co/t/real-time-vs-near-real-time-searching/8482>\
**Category:** Elasticsearch\
**Created:** [July 21, 2012, 3:14pm UTC](https://discuss.elastic.co/t/real-time-vs-near-real-time-searching/8482 "2012-07-21T15:14:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dkullmann](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dkullmann/32/2283_2.png) [@dkullmann](https://discuss.elastic.co/u/dkullmann)\
**Post date:** [July 21, 2012, 3:14pm UTC](https://discuss.elastic.co/t/real-time-vs-near-real-time-searching/8482/1 "2012-07-21T15:14:10Z")

</div>

Hello,

I'm writing unit tests for an ElasticSearch datasource, however, I am  
getting mixed results. The problem is that a match\_all query isn't finding  
records that I submitted, however, when I run the commands by hand using  
CURL in the same order the unit test does I am able to find the records.

I believe that perhaps the index isn't refreshed, so, I started running the  
"refresh" api command after submitting records, however, this didn't work  
either. Here is my list of commands - it would be helpful if anyone had any  
suggestions on how to make sure these commands worked even if they were run  
in immediate succession.

Commands the unit test runs:

curl -XGET '[http://localhost:9200/test\_index/\_mapping](http://localhost:9200/test_index/_mapping)'

curl -XDELETE '[http://localhost:9200/test\_index/test\_models](http://localhost:9200/test_index/test_models)'

curl -XPOST '[http://localhost:9200/test\_index/test\_models/\_refresh](http://localhost:9200/test_index/test_models/_refresh)' -d '{}'

curl -XPUT '[http://localhost:9200/test\_index/test\_models/\_mapping](http://localhost:9200/test_index/test_models/_mapping)' -d  
'{"test\_models":{"properties":{"TestModel":{"properties":{"id":{"type":"string","index":"not\_analyzed"},"string":{"type":"string"},"created":{"type":"date","format":"yyyy-MM-dd  
HH:mm:ss"},"modified":{"type":"date","format":"yyyy-MM-dd  
HH:mm:ss"}},"type":"object"}}}}'

curl -XPOST '[http://localhost:9200/test\_index/test\_models/\_bulk](http://localhost:9200/test_index/test_models/_bulk)' -d  
'{"index":{"\_index":"test\_index","\_type":"test\_models","\_id":"test-model"}}  
{"TestModel":{"id":"test-model","string":"Analyzed for  
terms","created":"2012-01-01 00:00:00","modified":"2012-02-01 00:00:00"}}  
'

curl -XPOST '[http://localhost:9200/test\_index/test\_models/\_refresh](http://localhost:9200/test_index/test_models/_refresh)' -d '{}'

curl -XGET '[http://localhost:9200/test\_index/\_mapping](http://localhost:9200/test_index/_mapping)'

curl -XGET '[http://localhost:9200/test\_index/test\_models/\_search](http://localhost:9200/test_index/test_models/_search)' -d  
'{"query":{"match\_all":{}},"size":10}'

Thanks,  
DK

---

<div class="post-metadata">

**Author:** ![dkullmann](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dkullmann/32/2283_2.png) [@dkullmann](https://discuss.elastic.co/u/dkullmann)\
**Post date:** [July 21, 2012, 3:15pm UTC](https://discuss.elastic.co/t/real-time-vs-near-real-time-searching/8482/2 "2012-07-21T15:15:47Z")

</div>

Note:

Adding "sleep 3" in my unit test between each command also worked,  
supporting the idea that the index isn't up to date.

Thanks!  
DK

On Saturday, July 21, 2012 11:14:10 AM UTC-4, David Kullmann wrote:

> Hello,
> 
> I'm writing unit tests for an Elasticsearch datasource, however, I am  
> getting mixed results. The problem is that a match\_all query isn't finding  
> records that I submitted, however, when I run the commands by hand using  
> CURL in the same order the unit test does I am able to find the records.
> 
> I believe that perhaps the index isn't refreshed, so, I started running  
> the "refresh" api command after submitting records, however, this didn't  
> work either. Here is my list of commands - it would be helpful if anyone  
> had any suggestions on how to make sure these commands worked even if they  
> were run in immediate succession.
> 
> Commands the unit test runs:
> 
> curl -XGET '[http://localhost:9200/test\_index/\_mapping](http://localhost:9200/test_index/_mapping)'
> 
> curl -XDELETE '[http://localhost:9200/test\_index/test\_models](http://localhost:9200/test_index/test_models)'
> 
> curl -XPOST '[http://localhost:9200/test\_index/test\_models/\_refresh](http://localhost:9200/test_index/test_models/_refresh)' -d  
> '{}'
> 
> curl -XPUT '[http://localhost:9200/test\_index/test\_models/\_mapping](http://localhost:9200/test_index/test_models/_mapping)' -d  
> '{"test\_models":{"properties":{"TestModel":{"properties":{"id":{"type":"string","index":"not\_analyzed"},"string":{"type":"string"},"created":{"type":"date","format":"yyyy-MM-dd  
> HH:mm:ss"},"modified":{"type":"date","format":"yyyy-MM-dd  
> HH:mm:ss"}},"type":"object"}}}}'
> 
> curl -XPOST '[http://localhost:9200/test\_index/test\_models/\_bulk](http://localhost:9200/test_index/test_models/_bulk)' -d  
> '{"index":{"\_index":"test\_index","\_type":"test\_models","\_id":"test-model"}}  
> {"TestModel":{"id":"test-model","string":"Analyzed for  
> terms","created":"2012-01-01 00:00:00","modified":"2012-02-01 00:00:00"}}  
> '
> 
> curl -XPOST '[http://localhost:9200/test\_index/test\_models/\_refresh](http://localhost:9200/test_index/test_models/_refresh)' -d  
> '{}'
> 
> curl -XGET '[http://localhost:9200/test\_index/\_mapping](http://localhost:9200/test_index/_mapping)'
> 
> curl -XGET '[http://localhost:9200/test\_index/test\_models/\_search](http://localhost:9200/test_index/test_models/_search)' -d  
> '{"query":{"match\_all":{}},"size":10}'
> 
> Thanks,  
> DK

---

<div class="post-metadata">

**Author:** ![dkullmann](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dkullmann/32/2283_2.png) [@dkullmann](https://discuss.elastic.co/u/dkullmann)\
**Post date:** [July 21, 2012, 3:23pm UTC](https://discuss.elastic.co/t/real-time-vs-near-real-time-searching/8482/3 "2012-07-21T15:23:17Z")

</div>

The problem is with the \_refresh command.

You can't refresh a type, only an index. I changed the refresh command to:

curl -XPOST '[http://localhost:9200/test\_index/\_refresh](http://localhost:9200/test_index/_refresh)[http://localhost:9200/test\_index/test\_models/\_refresh](http://localhost:9200/test_index/test_models/_refresh)  
'

And it is now fixed!

Thanks,  
DK

On Saturday, July 21, 2012 11:14:10 AM UTC-4, David Kullmann wrote:

> Hello,
> 
> I'm writing unit tests for an Elasticsearch datasource, however, I am  
> getting mixed results. The problem is that a match\_all query isn't finding  
> records that I submitted, however, when I run the commands by hand using  
> CURL in the same order the unit test does I am able to find the records.
> 
> I believe that perhaps the index isn't refreshed, so, I started running  
> the "refresh" api command after submitting records, however, this didn't  
> work either. Here is my list of commands - it would be helpful if anyone  
> had any suggestions on how to make sure these commands worked even if they  
> were run in immediate succession.
> 
> Commands the unit test runs:
> 
> curl -XGET '[http://localhost:9200/test\_index/\_mapping](http://localhost:9200/test_index/_mapping)'
> 
> curl -XDELETE '[http://localhost:9200/test\_index/test\_models](http://localhost:9200/test_index/test_models)'
> 
> curl -XPOST '[http://localhost:9200/test\_index/test\_models/\_refresh](http://localhost:9200/test_index/test_models/_refresh)' -d  
> '{}'
> 
> curl -XPUT '[http://localhost:9200/test\_index/test\_models/\_mapping](http://localhost:9200/test_index/test_models/_mapping)' -d  
> '{"test\_models":{"properties":{"TestModel":{"properties":{"id":{"type":"string","index":"not\_analyzed"},"string":{"type":"string"},"created":{"type":"date","format":"yyyy-MM-dd  
> HH:mm:ss"},"modified":{"type":"date","format":"yyyy-MM-dd  
> HH:mm:ss"}},"type":"object"}}}}'
> 
> curl -XPOST '[http://localhost:9200/test\_index/test\_models/\_bulk](http://localhost:9200/test_index/test_models/_bulk)' -d  
> '{"index":{"\_index":"test\_index","\_type":"test\_models","\_id":"test-model"}}  
> {"TestModel":{"id":"test-model","string":"Analyzed for  
> terms","created":"2012-01-01 00:00:00","modified":"2012-02-01 00:00:00"}}  
> '
> 
> curl -XPOST '[http://localhost:9200/test\_index/test\_models/\_refresh](http://localhost:9200/test_index/test_models/_refresh)' -d  
> '{}'
> 
> curl -XGET '[http://localhost:9200/test\_index/\_mapping](http://localhost:9200/test_index/_mapping)'
> 
> curl -XGET '[http://localhost:9200/test\_index/test\_models/\_search](http://localhost:9200/test_index/test_models/_search)' -d  
> '{"query":{"match\_all":{}},"size":10}'
> 
> Thanks,  
> DK

---

<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, 3:19am UTC](https://discuss.elastic.co/t/real-time-vs-near-real-time-searching/8482/4 "2017-07-06T03:19:31Z")

</div>


