Gentle introduction...
If you have access to REST API, you can majorly screw up things:
curl -X DELETE "http://localhost:9200/*"
That's right, you just emptied your cluster. One command, no confirmation.
2 main ways of searching in ES:
GET /<indiceName>/_search?q=person_id:5789758af6c0b483488b4735
Simple example
GET people_5/_search
{
"query": {
"match_all": {}
},
"sort": [
{
"date_updated": {
"order": "desc"
}
}
],
"from": 0,
"size": 20
}
Of course, match_all is not the only query type. Here's the most useful ones
GET /<indice/_search
{
"query": {
"match": {
"title": "Article title"
}
}
}
This will look for "Article title" in the field title of each documents
Ok, I'm lying: this is going to search for Article OR title inside the title of each documents, and boost accordingly.
This type of query will be analyzed according to index configuration (tokenising, stemming, synonyms etc)
GET /<indice/_search
{
"query": {
"multi_match": {
"query": "Article title",
"fields": ["title", "body"]
}
}
}
This will look for "Article title" in the both fields
GET /<indice/_search
{
"query": {
"term": {
"tag": "php"
}
}
}
This will look for the exact term "php" in the tag field.
Contrary to match and query_string, this type of queries are not analyzed: whatever you pass have to be exactly what's in the inverted index.
GET /<indice/_search
{
"query": {
"terms": {
"tag": ["php", "elasticsearch"]
}
}
}
This will look for any document having either php or elasticsearch as a tag.
GET /<indice/_search
{
"query": {
"bool": {
"must": [{
"term": {
"tag": "php"
}
}],
should: [
{
"term": {
"tag": "elasticsearch"
}
}
],
must_not: [
{
"term": {
"organization": "oracle"
}
}
],
filter: [
{
"term": {
"level": "good"
}
}
]
}
}
}
Must be, part of scoring
Should be, part of scoring
Must not be, not part of scoring
Must be, not part of scoring => cachable!
GET /<indice/_search
{
"query": {
"nested": {
"path": "profile",
"query": {
"bool": {
"filter": {
"terms": {
"profile.source": [
"public","hcareers","dice","rigzone","efinancialcareers"
]
}
},
"must": [
{"term": {
"profile.value.given_name": {
"value": "fabrice"
}
}}
]
}
}
}
}
}