# How to search data from URI by ID

**URL:** <https://discuss.elastic.co/t/how-to-search-data-from-uri-by-id/118795>\
**Category:** Elasticsearch\
**Created:** [February 7, 2018, 10:00am UTC](https://discuss.elastic.co/t/how-to-search-data-from-uri-by-id/118795 "2018-02-07T10:00:41Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Muhammad\_Yusuf](https://avatars.discourse-cdn.com/v4/letter/m/e36b37/32.png) [@Muhammad\_Yusuf](https://discuss.elastic.co/u/Muhammad_Yusuf)\
**Post date:** [February 7, 2018, 10:00am UTC](https://discuss.elastic.co/t/how-to-search-data-from-uri-by-id/118795/1 "2018-02-07T10:00:41Z")

</div>

Hi,  
I have problem when i try to search using URI method by ID  
i try to access  
[http://mydomain:9200/thisindex/thistype/\_search?q=\_id:\*\*](http://mydomain:9200/thisindex/thistype/_search?q=_id:**)  
[http://mydomain:9200/thisindex/thistype/\_search?q=id:\*\*](http://mydomain:9200/thisindex/thistype/_search?q=id:**)

elasticsearch response nothing no data  
but when i try to access  
[http://mydomain:9200/thisindex/thistype/\_search?q=\*:\*\*](http://mydomain:9200/thisindex/thistype/_search?q=*:**)  
all field they response

the question : i dont know how to filter by id using uri method  
i glad if you guys can help me for solved my problem

im sorry my english so bad.

---

<div class="post-metadata">

**Author:** ![Muhammad\_Yusuf](https://avatars.discourse-cdn.com/v4/letter/m/e36b37/32.png) [@Muhammad\_Yusuf](https://discuss.elastic.co/u/Muhammad_Yusuf)\
**Post date:** [February 8, 2018, 3:24am UTC](https://discuss.elastic.co/t/how-to-search-data-from-uri-by-id/118795/2 "2018-02-08T03:24:15Z")

</div>

[UPDATE]  
i try using spesific id , elastic response  
i try access [http://mydomain:9200/thisindex/thistype/\_search?q=\_id:001\_employee](http://mydomain:9200/thisindex/thistype/_search?q=_id:001_employee)

but my goal is filter all data with id contain word "employee"  
i try with access  
[http://mydomain:9200/thisindex/thistype/\_search?q=\_id:](http://mydomain:9200/thisindex/thistype/_search?q=_id:)_employee_  
cant get data based on id containt word "employee"

pls help me

---

<div class="post-metadata">

**Author:** ![val](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/val/32/138203_2.png) [@val](https://discuss.elastic.co/u/val)\
**Post date:** [February 8, 2018, 3:34am UTC](https://discuss.elastic.co/t/how-to-search-data-from-uri-by-id/118795/3 "2018-02-08T03:34:03Z")

</div>

The `_id` field is not analyzed so you can only retrieve a document if the id matches exactly.

If you have an `id` field within your source with the same value as `_id`, the story can be different, but it depends on how that `id` field is mapped. Can you share your mapping?

---

<div class="post-metadata">

**Author:** ![Muhammad\_Yusuf](https://avatars.discourse-cdn.com/v4/letter/m/e36b37/32.png) [@Muhammad\_Yusuf](https://discuss.elastic.co/u/Muhammad_Yusuf)\
**Post date:** [February 8, 2018, 3:46am UTC](https://discuss.elastic.co/t/how-to-search-data-from-uri-by-id/118795/4 "2018-02-08T03:46:27Z")

</div>

thanks mr val you response my question,  
i dont use mapping , but you're idea to create new field with same value as \_id is good idea  
but i must update my data one by one.  
im new using elasticsearch but i read any article if you want to use mapping you must  
reset your data and input again , it is right ??

but if there is no way again,  
cant helped i must trying use mapping

---

<div class="post-metadata">

**Author:** ![val](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/val/32/138203_2.png) [@val](https://discuss.elastic.co/u/val)\
**Post date:** [February 8, 2018, 3:57am UTC](https://discuss.elastic.co/t/how-to-search-data-from-uri-by-id/118795/5 "2018-02-08T03:57:23Z")

</div>

You could do this easily using the [reindex API](https://www.elastic.co/guide/en/elasticsearch/reference/6.2/docs-reindex.html):

```
POST _reindex
{
  "source": {
    "index": "source_index"
  },
  "dest": {
    "index": "new_index"
  },
  "script": {
    "source": "ctx._source.id = ctx._id"
  }
}

```

This will create a new `id` field inside your source having the same value as the `_id` field. However, if your `_id`s are of the form `001_employee` and you're willing to look for all documents whose id ends with `employee`, you might want to change your ids to `employee_001` instead as it is easier to search for prefixes than suffixes.

Does your index contain different data types? Why do you encode `employee` within your id?

---

<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:** [March 8, 2018, 3:57am UTC](https://discuss.elastic.co/t/how-to-search-data-from-uri-by-id/118795/6 "2018-03-08T03:57:23Z")

</div>

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