Elasticsearch Search API - elasticsearch - elasticsearch tutorial - elastic search
Elasticsearch Search API
- The API is utilized to look content in Elastic pursuit. Either a client can look by sending a get ask for with question string as a parameter or an inquiry in the message assortment of post ask. Chiefly all the inquiry APIS are multi-file, multi-sort.

learn elasticsearch tutorials - search api Example
Multi-Index
- Elastic search allows us to search for the documents present in all the indices or in some specific indices.
- For example, if we need to search all the documents with a name that contains central.
GET http://localhost:9200/_search?q = name:central
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - elasticsearch - elasticsearch tutorial - elastic - elastic search - elasticsearch docker team
Response
{
"took":78, "timed_out":false, "_shards":{"total":10, "successful":10, "failed":0},
"hits":{
"total":1, "max_score":0.19178301, "hits":[{
"_index":"schools", "_type":"school", "_id":"1", "_score":0.19178301,
"_source":{
"name":"Central School", "description":"CBSE Affiliation",
"street":"Nagan", "city":"paprola", "state":"HP", "zip":"176115",
"location":[31.8955385, 76.8380405], "fees":2000,
"tags":["Senior Secondary", "beautiful campus"], "rating":"3.5"
}
}]
}
}
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - elasticsearch - elasticsearch tutorial - elastic - elastic search - elasticsearch docker team
- Or, we can search for the same in schools, schools_gov indices
GET http://localhost:9200/schools,schools_gov/_search?q = name:model
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - elasticsearch - elasticsearch tutorial - elastic - elastic search - elasticsearch docker team
Multi-Type
- We can also search all the documents in an index across all types or in some specified type. For example,
Get http://localhost:9200/schools/_search?q = tags:sports
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - elasticsearch - elasticsearch tutorial - elastic - elastic search - elasticsearch docker team
Response
{
"took":16, "timed_out":false, "_shards":{"total":5, "successful":5, "failed":0},
"hits":{
"total":1, "max_score":0.5, "hits":[{
"_index":"schools", "_type":"school", "_id":"2", "_score":0.5,
"_source":{
"name":"Saint Paul School", "description":"ICSE Afiliation",
"street":"Dawarka", "city":"Delhi", "state":"Delhi", "zip":"110075",
"location":[28.5733056, 77.0122136], "fees":5000,
"tags":["Good Faculty", "Great Sports"], "rating":"4.5"
}
}]
}
}
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - elasticsearch - elasticsearch tutorial - elastic - elastic search - elasticsearch docker team
URI Search
- Many parameters can be passed in a search operation using Uniform Resource Identifier
Sr.No | Parameter & Description |
---|---|
1 | Q This parameter is used to specify query string. |
2 | lenient Format based errors can be ignored by just setting this parameter to true. It is false by default. |
3 | fields This parameter helps us to get response from selective fields. |
4 | sort We can get sorted result by using this parameter, the possible values for this parameter is fieldName, fieldName:asc/fieldname:desc |
5 | timeout We can restrict the search time by using this parameter and response only contains the hits in that specified time. By default, there is no timeout. |
6 | terminate_after We can restrict the response to a specified number of documents for each shard, upon reaching which the query will terminate early. By default, there is no terminate_after. |
7 | from The starting from index of the hits to return. Defaults to 0. |
8 | size It denotes the number of hits to return. Defaults to 10. |
Request Body Search
- We can also specify query using query DSL in request body and there are many examples already given in previous chapters like
POST http://localhost:9200/schools/_search
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - elasticsearch - elasticsearch tutorial - elastic - elastic search - elasticsearch docker team
Request Body
{
"query":{
"query_string":{
"query":"up"
}
}
}
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - elasticsearch - elasticsearch tutorial - elastic - elastic search - elasticsearch docker team
elasticsearch - elasticsearch tutorial - elastic search - elasticsearch sort - elasticsearch list indexes - elasticsearch node
Response
{
"_source":{
"name":"City School", "description":"ICSE", "street":"West End",
"city":"Meerut", "state":"UP", "zip":"250002", "location":[28.9926174, 77.692485],
"fees":3500, "tags":["Well equipped labs"],"rating":"4.5"
}
}