LIst All Indices
GET http://localhost:9200/_cat/indices?v
List all document in index
http://localhost:9200/example-index/_search
or
GET localhost:9200/example-index/_search?pretty
in application/json pass
{
"query": {
"match_all": {}
}
}
How to create index student
PUT localhost:9200/student
Drop Index
DELETE http://localhost:9200/country
Insert Data
POST http://localhost:9200/playgrund/_doc
{
"name":"sangram desai",
"age":45,
"place":"vikroli"
}
List all data in index
GET http://localhost:9200/playgrund/_search?pretty=true
Other
GET localhost:9200/playgrund/_search?&scroll=10m&size=50
{
"query" : {
"match_all" : {}
}
}
or
GET localhost:9200/playgrund/_search?&scroll=10m&size=50
{
"size": 10,
"from": 0,
"query": {
"match_all": {}
}
}
Search by key
GET localhost:9200/playgrund/_search
{
"query": {
"match": {
"place" : "vikroli"
}
}
}
Like Search
GET localhost:9200/playgrund/_search
{
"query": {
"wildcard": {
"place": "vik*"
}
}
}
Start With
GET localhost:9200/playgrund/_search
{
"query": {
"prefix": {
"place": "v"
}
}
}
Like another
GET localhost:9200/playgrund/_search
{
"query": {
"wildcard": {
"place": "*li"
}
}
}
Regx query
GET localhost:9200/playgrund/_search
{
"query": {
"regexp": {
"place": {
"value": "vik.*",
"flags": "COMPLEMENT"
}
}
}
}
another
GET localhost:9200/playgrund/_search
{
"query": {
"regexp": {
"place": {
"value": ".ik.*",
"flags": "COMPLEMENT"
}
}
}
}
PIck only required column
GET netflix/_search?&scroll=10m&size=50
{
"_source":["director"],
"size": 1,
"from": 0,
"query": {
"bool": {
"must": [],
"filter": [],
"should": [],
"must_not": []
}
}
}
Field Exist
GET netflix/_search?&scroll=10m&size=50
{
"_source":[],
"size": 1,
"from": 0,
"query": {
"bool": {
"must": [],
"filter": [
{
"exists": {
"field": "title"
}
}
],
"should": [],
"must_not": []
}
}
}
Match Phrase
GET netflix/_search?&scroll=10m&size=50
{
"_source":[],
"size": 1,
"from": 0,
"query": {
"bool": {
"must": [],
"filter": [
{
"exists": {
"field": "title"
}
}
],
"should": [
{
"match_phrase": {
"title": "rocky"
}
}],
"must_not": []
}
}
}
Aggregation
GET netflix/_search?&scroll=10m&size=50
{
"_source":[],
"size": 1,
"from": 0,
"query": {
"bool": {
"must": [],
"filter": [
{
"exists": {
"field": "duration"
}
}
],
"should": [],
"must_not": []
}
},
"aggs": {
"mybucket": {
"terms": {
"field": "duration",
"order": {
"_count": "desc"
},
"size": 5
}
}
}
}
other
GET netflix/_search?&scroll=10m&size=50
{
"_source":[],
"size": 1,
"from": 0,
"query": {
"bool": {
"must": [],
"filter": [
{
"exists": {
"field": "rating"
}
}
],
"should": [],
"must_not": []
}
},
"aggs": {
"mybucket": {
"terms": {
"field": "rating",
"order": {
"_count": "desc"
},
"size": 5
}
}
}
Composite Aggregation
GET netflix/_search?&scroll=10m&size=50
{
"_source":[],
"size": 1,
"from": 0,
"query": {
"bool": {
"must": [],
"filter": [
],
"should": [],
"must_not": []
}
},
"aggs": {
"mybucket": {
"composite": {
"sources": [
{
"myaggre": {
"terms": {
"field": "rating",
"order":"desc"
}
}
}
]
}
}
}
}
Composite Aggregation:
GET netflix/_search?&scroll=10m&size=50
{
"_source":[],
"size": 1,
"from": 0,
"query": {
"bool": {
"must": [],
"filter": [
],
"should": [],
"must_not": []
}
},
"aggs": {
"mybucket": {
"composite": {
"sources": [
{
"myaggre": {
"terms": {
"field": "rating",
"order":"desc"
}
}
},
{
"mynewaggre": {
"terms": {
"field": "duration"
}
}
}
]
}
}
}
}
Suggestion:
GET netflix/_search?&scroll=10m&size=50
{
"_source":[
"director"
],
"size": 1,
"from": 0,
"query": {
"bool": {
"must": [],
"filter": [
],
"should": [],
"must_not": []
}
},
"suggest": {
"mysuggestion": {
"text": "Kirsten John",
"term": {
"field": "director"
}
}
}
}
}
No comments:
Post a Comment