# Unsuccessful Search

**URL:** <https://discuss.elastic.co/t/unsuccessful-search/136122>\
**Category:** Elasticsearch\
**Created:** [June 15, 2018, 5:05pm UTC](https://discuss.elastic.co/t/unsuccessful-search/136122 "2018-06-15T17:05:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrbarret](https://avatars.discourse-cdn.com/v4/letter/m/a9adbd/32.png) [@mrbarret](https://discuss.elastic.co/u/mrbarret)\
**Post date:** [June 15, 2018, 5:05pm UTC](https://discuss.elastic.co/t/unsuccessful-search/136122/1 "2018-06-15T17:05:54Z")

</div>

I am using Elastic Search (and Kibana) v 6.3.0. I am unable to obtain search results through the RestHighLevelClient that appear using Kibana. Here are the steps to reproduce by issue, please let me know what you think.

Using the transport client I submit

```
CreateIndexRequest createIndexRequest = new 
CreateIndexRequest("phenotype");
Settings settings = Settings.builder()
        .put("index.number_of_replicas", 2)
        .put("index.number_of_shards", 3)
        .build();
createIndexRequest.settings(settings);
CreateIndexResponse createIndexResponse = 
transportClient.admin().indices().create(createIndexRequest).actionGet();

```

Then I submit a mapping update for a field name called key1 giving it the field type keyword. Using the Kibana Dev Tools tab and the command `GET /phenotype/_mappings` I can verify that both steps are successful.

I save a document to Elastic Search with the command

```
IndexResponse indexResponse = elasticSearchRepository.save(document1); 

```

which contains only the information `key1: value1`.

Executing the command, from Kibana,

```
GET /phenotype/_search
{
  "query": {
    "term" : {
      "key1" : {
        "value" : "value1",
        "boost" : 1.0
      }
    }
  }
}

```

I see that the correct data is returned, being

```
{
  "took": 1,
  "timed_out": false,
  "_shards": {
    "total": 3,
    "successful": 3,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 1,
    "max_score": 0.2876821,
    "hits": [
      {
        "_index": "phenotype",
        "_type": "phenotype",
        "_id": "685c3d59-4315-4f63-bf6a-17ad8a20aede",
        "_score": 0.2876821,
        "_source": {
          "key1": "value1"
        }
      }
    ]
  }
}

```

But when I execute the search command through the Java REST API I receive zero search hits. This is how I do it.

```
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder()
    .query(
          QueryBuilders.termQuery("key1", "value1")
    );
SearchRequest searchRequest = new SearchRequest("phenotype");
searchRequest.source(searchSourceBuilder);
return restHighLevelClient.search(searchRequest);

```

WHY?!

---

<div class="post-metadata">

**Author:** ![mrbarret](https://avatars.discourse-cdn.com/v4/letter/m/a9adbd/32.png) [@mrbarret](https://discuss.elastic.co/u/mrbarret)\
**Post date:** [June 18, 2018, 1:15pm UTC](https://discuss.elastic.co/t/unsuccessful-search/136122/2 "2018-06-18T13:15:49Z")

</div>

The solution was to sleep for 1 second after saving the document to ES, before searching for it.

Why does the save method receive `Rest.CREATED` when sleep is still required?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [June 18, 2018, 2:06pm UTC](https://discuss.elastic.co/t/unsuccessful-search/136122/3 "2018-06-18T14:06:57Z")

</div>

You can add the `refresh=wait_for` option in the context of tests or `refresh=true` to make your documents immediately visible for search.

See [https://www.elastic.co/guide/en/elasticsearch/reference/6.3/docs-refresh.html](https://www.elastic.co/guide/en/elasticsearch/reference/6.3/docs-refresh.html)

---

<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 16, 2018, 2:07pm UTC](https://discuss.elastic.co/t/unsuccessful-search/136122/4 "2018-07-16T14:07:11Z")

</div>

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