Last active
June 30, 2020 17:34
-
-
Save rajivmehtaflex/baa0f412a889eb468eb1b14b6bba0291 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1. | |
curl --silent --request POST 'http://localhost:9200/movies/_analyze?pretty' \ | |
--data-raw '{ | |
"tokenizer" : "standard", | |
"filter": [{"type":"edge_ngram", "min_gram": 1, "max_gram": 4}], | |
"text" : "Star" | |
}' | |
2. | |
curl --request PUT 'http://localhost:9200/autocomplete' \ | |
-d '{ | |
"mappings": { | |
"properties": { | |
"title": { | |
"type": "search_as_you_type" | |
}, | |
"genre": { | |
"type": "search_as_you_type" | |
} | |
} | |
} | |
}' | |
3. | |
curl --silent --request POST 'http://localhost:9200/_reindex?pretty' --data-raw '{ | |
"source": { | |
"index": "movies" | |
}, | |
"dest": { | |
"index": "autocomplete" | |
} | |
}' | grep "total\|created\|failures" | |
4. | |
curl -s --request GET 'http://localhost:9200/autocomplete/_search?pretty' --data-raw '{ | |
"size": 5, | |
"query": { | |
"multi_match": { | |
"query": "Sta", | |
"type": "bool_prefix", | |
"fields": [ | |
"title", | |
"title._2gram", | |
"title._3gram" | |
] | |
} | |
} | |
}' | |
5. | |
while true | |
do | |
IFS= read -rsn1 char | |
INPUT=$INPUT$char | |
echo $INPUT | |
curl --silent --request GET 'http://localhost:9200/autocomplete/_search' \ | |
--data-raw '{ | |
"size": 5, | |
"query": { | |
"multi_match": { | |
"query": "'"$INPUT"'", | |
"type": "bool_prefix", | |
"fields": [ | |
"title", | |
"title._2gram", | |
"title._3gram" | |
] | |
} | |
} | |
}' | jq .hits.hits[]._source.title | grep -i "$INPUT" | |
done | |
================================================One More Example================================== | |
PUT gmm | |
{ | |
"mappings": { | |
"properties": { | |
"firstname":{ | |
"type":"text", | |
"fields": { | |
"raw":{"type":"keyword"}, | |
"lookref":{"type":"search_as_you_type"} | |
} | |
} | |
} | |
} | |
} | |
PUT /gmm/_doc/4 | |
{ | |
"firstname":"kano" | |
} | |
GET /gmm/_search?pretty&explain | |
{ | |
"size": 20, | |
"query": { | |
"multi_match": { | |
"query": "Ka", | |
"type": "bool_prefix", | |
"fields": [ | |
"firstname.lookref", | |
"firstname.lookref._2gram", | |
"firstname.lookref._3gram" | |
] | |
} | |
} | |
} | |
=========================================== | |
GET /cf_etf/_search | |
{ | |
"query": { | |
"query_string": { | |
"default_field": "symbol", | |
"query": "ACWF ACWI", | |
"default_operator": "OR" | |
} | |
}, | |
"_source": [ | |
"fund_name","category","symbol" | |
], | |
"sort": [ | |
{ | |
"symbol.keyword": { | |
"order": "desc" | |
} | |
} | |
] | |
} | |
GET /cf_etf/_search | |
{ | |
"from": 0, | |
"size": 20, | |
"query": { | |
"match_all": {} | |
} | |
} | |
POST _sql?format=json | |
{ | |
"query": """ | |
select * from store | |
""", | |
"fetch_size":2 | |
} | |
POST _sql?format=json | |
{ | |
"cursor":"q9qtAwFaAXNARFhGMVpYSjVRVzVrUm1WMFkyZ0JBQUFBQUFBQUhOQVdkRGxsYUZkMVZVaFNaaTFsWTBObVJHaDJWRGw2ZHc9Pf////8PBgFmCkB0aW1lc3RhbXABCkB0aW1lc3RhbXABCGRhdGV0aW1lAQAAAWYIQHZlcnNpb24BCEB2ZXJzaW9uAQR0ZXh0AAAAAWYKZGVwYXJ0bWVudAEKZGVwYXJ0bWVudAEHa2V5d29yZAEAAAFmBG5hbWUBBG5hbWUBBHRleHQAAAABZgVwcmljZQEFcHJpY2UBBmRvdWJsZQAAAAFmCHF1YW50aXR5AQhxdWFudGl0eQEHaW50ZWdlcgAAAAE/" | |
} | |
GET store/_search?scroll | |
{ | |
"scroll":"10m", | |
"scroll_id":"DXF1ZXJ5QW5kRmV0Y2gBAAAAAAAAO7MWdDllaFd1VUhSZi1lY0NmRGh2VDl6dw==" | |
} | |
GET cf_etf/_search?scroll=10m | |
{ | |
"size": 20 | |
} | |
GET _search/scroll | |
{ | |
"scroll_id":"DXF1ZXJ5QW5kRmV0Y2gBAAAAAAAAPB8WdDllaFd1VUhSZi1lY0NmRGh2VDl6dw==", | |
"scroll":"10m" | |
} | |
DELETE _search/scroll | |
{ | |
"scroll_id":["DXF1ZXJ5QW5kRmV0Y2gBAAAAAAAAPB8WdDllaFd1VUhSZi1lY0NmRGh2VDl6dw=="] | |
} | |
GET cf_etf/_mapping | |
GET cf_etf/_search | |
{ | |
"_source": "fund_name", | |
"size": 20 | |
} | |
GET cf_etf/_search | |
{ | |
"_source": "fund_name", | |
"query": { | |
"match_phrase": { | |
"fund_name":{ | |
"query": "ishares global" | |
} | |
} | |
} | |
} | |
POST /_analyze | |
{ | |
"text": ["Gajraj ni jai ho"], | |
"tokenizer": "standard", | |
"filter": ["lowercase"] | |
} | |
PUT gmm | |
PUT /gmm/_mapping | |
{ | |
"properties": { | |
"targetf": { | |
"type": "search_as_you_type", | |
"fields": { | |
"row":{ | |
"type":"text" | |
}, | |
"keydata":{ | |
"type":"keyword" | |
} | |
} | |
} | |
} | |
} | |
POST /_reindex | |
{ | |
"source": { | |
"index": "gmm" | |
}, | |
"dest": { | |
"index": "gmmv1" | |
} | |
} | |
DELETE gmm | |
PUT /gmm/_doc/4 | |
{ | |
"targetf":"Gonda" | |
} | |
GET /gmm/_search | |
{ | |
"query": { | |
"match_all": { | |
} | |
} | |
} | |
GET /gmm/_search?pretty | |
{ | |
"size": 20, | |
"query": { | |
"multi_match": { | |
"query": "B", | |
"type": "bool_prefix", | |
"fields": [ | |
"targetf","targetf._2gram","targetf._3gram" | |
] | |
} | |
} | |
} | |
=========================================================Alias OPS=================================================== | |
//Define alias with index | |
PUT /gmm/_alias/explorer | |
//Get Mapping with alias | |
GET /explorer/_mapping | |
//Insert data with alias | |
PUT /explorer/_doc/2 | |
{ | |
"firstname":"krishan", | |
"lastname":"yadav" | |
} | |
//GET Data with mapping | |
GET explorer/_search | |
{ | |
"_source": "firstname", | |
"query": { | |
"match_all": {} | |
} | |
} | |
//Get data with original index | |
GET /gmm/_search | |
//Get list of alias | |
GET /_alias | |
// Reset alias and point to other index | |
POST /_reindex | |
{ | |
"source": { | |
"index": "gmm" | |
}, | |
"dest": { | |
"index": "gmmv1" | |
} | |
} | |
// perform ops on other index | |
PUT /gmmv1/_doc/3 | |
{ | |
"firstname":"Mantra", | |
"lastname":"Mehta" | |
} | |
==============================================Backup/Restore OPS================================================ | |
//Create Repo | |
// set We need to edit config/elasticsearch.yml and add the directory of your backup | |
repository – path.repo: /backup/. | |
PUT /_snapshot/grepo | |
{ | |
"type": "fs", | |
"settings": { | |
"location": "/home/backup", | |
"compress":true | |
} | |
} | |
// Get repo info | |
GET /_snapshot/grepo | |
// Create a Backup | |
PUT /_snapshot/grepo/snap_1?wait_for_completion=true | |
{ | |
"indices": "gmm*", | |
"ignore_unavailable": "true", | |
"include_global_state": false | |
} | |
//DELETE _snapshot | |
DELETE /_snapshot/grepo/snap_1 | |
//Restore Snapshot | |
POST /_snapshot/grepo/snap_1/_restore | |
{ | |
"indices": "gmm*", | |
"ignore_unavailable": "true", | |
"include_global_state": false, | |
"rename_pattern": "gmm-(.+)", | |
"rename_replacement": "copy_$1" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment