How to search data from URI by ID


(Muhammad Yusuf) #1

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:**

elasticsearch response nothing no data
but when i try to access
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.


(Muhammad Yusuf) #2

[UPDATE]
i try using spesific id , elastic response
i try access 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:employee
cant get data based on id containt word "employee"

pls help me


(Val Crettaz) #3

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?


(Muhammad Yusuf) #4

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


(Val Crettaz) #5

You could do this easily using the reindex API:

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 _ids 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?


(system) #6

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