Skip to content

Instantly share code, notes, and snippets.

@cminovici
Created July 3, 2018 13:56
Show Gist options
  • Save cminovici/7d9187208c6e9d4ea9f6ff8de54912be to your computer and use it in GitHub Desktop.
Save cminovici/7d9187208c6e9d4ea9f6ff8de54912be to your computer and use it in GitHub Desktop.
Clusterul este - scm-log.emag.network
Format din masinile:
scm-log1-all-prod.emag.network
scm-elastic1-all-prod.emag.network
scm-elastic2-all-prod.emag.network
scm-elastic3-all-prod.emag.network
curl -XGET 'http://scm-elastic3-all-prod.emag.network:9200/_cat/indices?v' -H 'Content-Type: application/json' -d '{}'
curl -XGET 'http://scm-elastic3-all-prod.emag.network:9200/logstash-scmr_*/_stats?format=json' -H 'Content-Type: application/json' -d '{}'
curl -XGET 'localhost:9200/_cat/indices?v' -d '{}'
curl -XGET 'localhost:9200/gitstash/_mapping?pretty'
################
## INDEX API ##
################
curl -XPUT 'localhost:9200/gitstash?pretty' -H 'Content-Type: application/json' -d'
{
"mappings": {
"commits": {
"properties": {
"changesets": {
"properties": {
"values": {
"properties": {
"changes": {
"properties": {
"values": { "type": "nested" }
}
}
}
}
}
}
}
}
}
}
'
curl -XPUT 'localhost:9200/scm?pretty' -H 'Content-Type: application/json' -d'
{
"settings" : {
"index" : {
"number_of_shards" : 3
}
}
}
'
curl -XPUT 'localhost:9200/scm/_doc/1?pretty' -H 'Content-Type: application/json' -d'
{
"user" : "foo",
"post_date" : "2018-02-19T14:12:12",
"message" : "My first index"
}
'
curl -XPUT 'localhost:9200/scm/_doc/1?version=2&pretty' -H 'Content-Type: application/json' -d'
{
"message" : "Now my first index has versioning support, double cool!"
}
'
################
## SEARCH API ##
################
curl -XGET 'localhost:9200/scm/_doc/0?pretty'
curl -XGET 'localhost:9200/app/_search?q=partnumber:aaoioijaoiIIIOIIOI&pretty=true' -d '{}'
# Full-text search
# https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query.html
curl -XGET 'localhost:9200/app/_search?pretty' -H 'Content-Type: application/json' -d'
{
"query": {
"match" : {
"partnumber" : "B078J4HKSY"
}
}
}
'
# Term query : Finds documents which contain the exact term B078J4HKSY in the inverted index of the partnumber field.
# https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-term-query.html
curl -XGET 'localhost:9200/_search?pretty' -H 'Content-Type: application/json' -d'
{
"query": {
"term" : { "partnumber" : "B078J4HKSY" }
}
}
'
# Like
# https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-mlt-query.html
curl -XGET 'localhost:9200/_search?pretty' -H 'Content-Type: application/json' -d'
{
"query": {
"more_like_this" : {
"fields" : ["name", "partnumber"],
"like" : "apple",
"min_term_freq" : 1,
"max_query_terms" : 12
}
}
}
'
curl -XGET 'localhost:9200/_search?pretty' -H 'Content-Type: application/json' -d'
{
"from" : 0, "size" : 10,
"query": {
"filtered": {
"query": {
"more_like_this" : {
"fields" : ["name", "partnumber"],
"like" : "apple",
"min_term_freq" : 1,
"max_query_terms" : 12
}
},
"filter": {
"not": {
"term": {
"status": "active"
}
}
}
}
}
}
'
curl -XGET 'localhost:9200/_search?pretty' -H 'Content-Type: application/json' -d'
{
"from" : 0, "size" : 10,
"filter": {
"bool": {
"must": {
"more_like_this" : {
"fields" : ["name", "partnumber"],
"like" : "apple",
"min_term_freq" : 1,
"max_query_terms" : 12
}
},
"filter": {
"not": {
"term": {
"status": "active"
}
}
},
"must_not": {
"match_phrase_prefix": {
"partnumber": "RSGE"
}
}
}
}
}
'
################
## DELETE API ##
################
curl -XDELETE 'localhost:9200/scm?pretty'
curl -XDELETE 'localhost:9200/scm/_doc/1?pretty'
curl -XPOST 'localhost:9200/scm/_delete_by_query?pretty' -H 'Content-Type: application/json' -d'
{
"query": {
"match": {
"message": "some message"
}
}
}
'
################
## UPDATE API ##
################
curl -XPOST 'localhost:9200/scm/_doc/1/_update?pretty' -H 'Content-Type: application/json' -d'
{
"doc" : {
"tags" : [ "testing" ],
"views": 0
}
}
'
# https://www.elastic.co/guide/en/elasticsearch/reference/current/docs.html
# https://gist.github.com/saiglen/ad8b89836547c7e0ee60
# https://www.elastic.co/blog/managing-relations-inside-elasticsearch
# https://discuss.elastic.co/t/querying-a-multiple-level-nested-object/56889/4
# https://www.elastic.co/guide/en/elasticsearch/reference/current/nested.html
# https://qbox.io/blog/minimizing-document-duplication-in-elasticsearch
# https://qbox.io/blog/elasticsearch-aggregations-nested-documents-tutorial
# https://zaiste.net/concisely_about_aggregations_in_elasticsearch/
curl -XGET 'localhost:9200/gitstash/_search?q="tests/ViewBundle/Service/ReceptionExportServiceTest.php"&pretty=true' -d '{}' | grep -a10 -b10 "tests/ViewBundle/Service/ReceptionExportServiceTest.php"
curl -XGET 'localhost:9200/gitstash/_count?q="tests/ViewBundle/Service/ReceptionExportServiceTest.php"&pretty=true'
curl -XPOST 'localhost:9200/gitstash/commits/_search' -d '{
"size": 0,
"aggs": {
"commit_changes": {
"nested": {
"path": "changesets.values.changes.values"
},
"aggs": {
"duplicateCount": {
"terms": {
"field": "changesets.values.changes.values.path.toString.raw",
"min_doc_count": 2
},
"aggs": {
"duplicateDocuments": {
"top_hits": {}
}
}
}
}
}
}
}'
curl -XPUT 'localhost:9200/gitstash?pretty' -H 'Content-Type: application/json' -d'
{
"mappings": {
"commits": {
"properties": {
"repository": {
"properties": {
"slug": {
"type": "string",
"fields": {
"raw": {
"type": "string",
"index": "not_analyzed"
}
}
}
}
},
"refChanges": {
"properties": {
"refId": {
"type": "string",
"fields": {
"raw": {
"type": "string",
"index": "not_analyzed"
}
}
}
}
},
"changesets": {
"properties": {
"values": {
"type": "nested",
"include_in_parent": true,
"properties": {
"toCommit": {
"properties": {
"committer": {
"properties": {
"emailAddress": {
"type": "string",
"fields": {
"raw": {
"type": "string",
"index": "not_analyzed"
}
}
}
}
},
"parents": {
"type": "nested"
}
}
},
"changes": {
"properties": {
"values": {
"type": "nested",
"include_in_parent": true,
"properties": {
"path": {
"properties": {
"toString": {
"type": "string",
"fields": {
"raw": {
"type": "string",
"index": "not_analyzed"
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
'
curl -XPOST 'localhost:9200/gitstash/commits/_search' -d '{
"size": 0,
"aggs": {
"commit_changes": {
"nested": {
"path": "changesets.values.changes.values"
},
"aggs": {
"duplicateCount": {
"terms": {
"field": "changesets.values.changes.values.path.toString.raw",
"min_doc_count": 2
},
"aggs": {
"duplicateDocuments": {
"reverse_nested": {},
"aggs": {
"changed_by": {
"nested": {
"path": "changesets.values"
},
"aggs": {
"email": {
"terms": {
"field": "changesets.values.toCommit.committer.emailAddress.raw"
}
}
}
}
}
}
}
}
}
}
}
}'
curl -XPOST 'localhost:9200/gitstash/commits/_search' -d '{
"size": 0,
"query": {
"bool": {
"filter": {
"not": {
"term": {
"refChanges.fromHash": "0000000000000000000000000000000000000000"
}
}
}
}
},
"aggs": {
"commit_changes": {
"nested": {
"path": "changesets.values.changes.values"
},
"aggs": {
"duplicateCount": {
"terms": {
"field": "changesets.values.changes.values.path.toString.raw",
"min_doc_count": 2
},
"aggs": {
"duplicateDocuments": {
"reverse_nested": {},
"aggs": {
"changed_by": {
"nested": {
"path": "changesets.values"
},
"aggs": {
"email": {
"terms": {
"field": "changesets.values.toCommit.committer.emailAddress.raw"
}
}
}
}
}
}
}
}
}
}
}
}'
curl -XPOST 'http://catalin-minovici-dev.gen-elastic14212-all-dev.scm-delta.c.emag.network:9200gitstash/commits/_search' -d '{
"size": 0,
"query": {
"bool": {
"filter": {
"not": {
"term": {
"refChanges.fromHash": "0000000000000000000000000000000000000000"
}
}
}
}
},
"aggs": {
"commit_changes": {
"nested": {
"path": "changesets.values.changes.values"
},
"aggs": {
"duplicateCount": {
"terms": {
"field": "changesets.values.changes.values.path.toString.raw",
"min_doc_count": 2
},
"aggs": {
"duplicateDocuments": {
"reverse_nested": {},
"aggs": {
"changed_by": {
"nested": {
"path": "changesets.values"
},
"aggs": {
"email": {
"terms": {
"field": "changesets.values.toCommit.committer.emailAddress.raw"
},
"aggs": {
"branch_name": {
"reverse_nested": {},
"aggs": {
"branch": {
"terms": {
"field": "refChanges.refId.raw"
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}'
curl -XPOST 'http://catalin-minovici-dev.gen-elastic14212-all-dev.scm-delta.c.emag.network:9200gitstash/commits/_search' -d '{
"size": 0,
"query": {
"bool": {
"filter": {
"and": [
{
"terms": {
"refChanges.type": [
"update"
]
}
},
{
"range": {
"changesets.size": {
"lte": 10
}
}
}
]
},
"must_not": {
"term": {
"refChanges.refId.raw": "refs/heads/master"
}
}
}
},
"aggs": {
"commit_changes": {
"nested": {
"path": "changesets.values.changes.values"
},
"aggs": {
"duplicateCount": {
"terms": {
"field": "changesets.values.changes.values.path.toString.raw",
"min_doc_count": 2
},
"aggs": {
"duplicateDocuments": {
"reverse_nested": {},
"aggs": {
"changed_by": {
"nested": {
"path": "changesets.values"
},
"aggs": {
"uniques": {
"cardinality": {
"field": "changesets.values.toCommit.committer.emailAddress.raw"
}
},
"email": {
"terms": {
"field": "changesets.values.toCommit.committer.emailAddress.raw"
},
"aggs": {
"branch_name": {
"reverse_nested": {},
"aggs": {
"branch": {
"terms": {
"field": "refChanges.refId.raw"
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}'
curl -XPOST 'http://catalin-minovici-dev.gen-elastic14212-all-dev.scm-delta.c.emag.network:9200gitstash/commits/_search' -d '{
"size": 0,
"query": {
"bool": {
"filter": {
"and": [
{
"terms": {
"refChanges.type": [
"update"
]
}
},
{
"range": {
"changesets.size": {
"lte": 10
}
}
}
]
},
"must": [
{
"script": {
"script": "_source.changesets.values.toCommit.parents.size() < 2"
}
}
],
"must_not": [
{
"term": {
"refChanges.refId.raw": "refs/heads/master"
}
}
]
}
},
"aggs": {
"commit_changes": {
"nested": {
"path": "changesets.values.changes.values"
},
"aggs": {
"duplicateCount": {
"terms": {
"field": "changesets.values.changes.values.path.toString.raw",
"min_doc_count": 2
},
"aggs": {
"duplicateDocuments": {
"reverse_nested": {},
"aggs": {
"changed_by": {
"nested": {
"path": "changesets.values"
},
"aggs": {
"uniques": {
"cardinality": {
"field": "changesets.values.toCommit.committer.emailAddress.raw"
}
},
"email": {
"terms": {
"field": "changesets.values.toCommit.committer.emailAddress.raw"
},
"aggs": {
"branch_name": {
"reverse_nested": {},
"aggs": {
"branch": {
"terms": {
"field": "refChanges.refId.raw"
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}'
curl -XPOST 'http://catalin-minovici-dev.gen-elastic14212-all-dev.scm-delta.c.emag.network:9200gitstash/commits/_search' -d '{
"size": 20,
"query": {
"bool": {
"filter": {
"and": [
{
"terms": {
"refChanges.type": [
"update",
"add"
]
}
}
]
},
"must": [
{
"script": {
"script": "_source.changesets.values.toCommit.parents.size() < 2"
}
}
],
"must_not": [
{
"term": {
"refChanges.refId.raw": "refs/heads/master"
}
}
]
}
},
"aggs": {
"app_name": {
"terms": {
"field": "repository.slug.raw"
},
"aggs": {
"commit_changes": {
"nested": {
"path": "changesets.values.changes.values"
},
"aggs": {
"duplicateCount": {
"terms": {
"field": "changesets.values.changes.values.path.toString.raw",
"min_doc_count": 2
},
"aggs": {
"duplicateDocuments": {
"reverse_nested": {},
"aggs": {
"changed_by": {
"nested": {
"path": "changesets.values"
},
"aggs": {
"uniques": {
"cardinality": {
"field": "changesets.values.toCommit.committer.emailAddress.raw"
}
},
"email": {
"terms": {
"field": "changesets.values.toCommit.committer.emailAddress.raw"
},
"aggs": {
"branch_name": {
"reverse_nested": {},
"aggs": {
"branch": {
"terms": {
"field": "refChanges.refId.raw"
},
"aggs": {
"info": {
"top_hits": {
"size": 5,
"_source": {
"include": "changesets.values.links"
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment