ElasticSearch - ΠΏΠΎΠΈΡΠΊΠΎΠ²ΡΠΉ Π΄Π²ΠΈΠΆΠΎΠΊ Ρ JSON REST API, ΠΈΡΠΏΠΎΠ»ΡΠ·ΡΡΡΠΈΠΉ ΠΏΠΎΠ΄ ΠΊΠ°ΠΏΠΎΡΠΎΠΌ Lucene. ΠΡΠ΅Π΄Π»Π°Π³Π°Ρ ΡΠΌΠ°ΡΡΠ΅ΡΠΈΡΡ Ρ ΠΏΠΎΠΌΠΎΡΡΡ Elastic ΠΏΠΎΠΈΡΠΊ Π΄Π»Ρ ΠΏΠ°ΡΠΎΡΠΊΠΈ ΡΠΈΠ»ΡΠΌΠΎΠ². ΠΠ° ΠΏΠ΅ΡΠ²ΠΎΠΌ ΡΡΠ°ΠΏΠ΅ ΡΠ°ΡΡΠΌΠΎΡΡΠΈΠΌ ΡΡΡΠ°Π½ΠΎΠ²ΠΊΡ ΠΈ Π½Π°ΡΡΡΠΎΠΉΠΊΠ° Elastic Π² Docker ΠΊΠΎΠ½ΡΠ΅ΠΉΠ½Π΅ΡΠ΅, Π²ΠΏΡΠΎΡΠ΅ΠΌ ΡΡΠΎ ΠΎΠΏΡΠΈΠΎΠ½Π°Π»ΡΠ½ΠΎ - Π²Ρ ΠΌΠΎΠΆΠ΅ΡΠ΅ ΡΡΡΠ°Π½ΠΎΠ²ΠΈΡΡ Elastic Π»ΡΠ±ΡΠΌ Π΄ΡΡΠ³ΠΈΠΌ ΡΠΏΠΎΡΠΎΠ±ΠΎΠΌ. ΠΠ°ΡΠ΅ΠΌ ΠΊΠΎΠΏΠ½ΡΠΌ ΠΏΠΎΠ³Π»ΡΠ±ΠΆΠ΅ Π² ΠΏΡΠΎΡΠ΅ΡΡ ΠΈΠ½Π΄Π΅ΠΊΡΠ°ΡΠΈΠΈ, ΠΏΠΎΠΈΡΠΊΠΎΠ²ΡΠ΅ Π·Π°ΠΏΡΠΎΡΡ,
ΠΏΠΎΠ΄ΡΠ²Π΅ΡΠΊΡ Π²Ρ
ΠΎΠΆΠ΄Π΅Π½ΠΈΠΉ Π² ΡΠ΅Π·ΡΠ»ΡΡΠ°ΡΠ°Ρ
Π²ΡΠ΄Π°ΡΠΈ ΠΈ Π°Π³ΡΠ΅Π³Π°ΡΠΈΡ Π΄Π°Π½Π½ΡΡ
Π² Elastic ΠΈ Π²ΡΡ ΡΡΠΎ ΡΠΎΠ»ΡΠΊΠΎ Π»ΠΈΡΡ Ρ ΠΏΠΎΠΌΠΎΡΡΡ REST API Π±Π΅Π· Π½Π΅ΠΎΠ±Ρ
ΠΎΠ΄ΠΈΠΌΠΎΡΡΠΈ Π½Π°Π»ΠΈΡΠΈΡ ΠΊΠ°ΠΊΠΈΡ
-Π»ΠΈΠ±ΠΎ Π³Π»ΡΠ±ΠΎΠΊΠΈΡ
ΠΏΠΎΠ·Π½Π°Π½ΠΈΠΉ ΠΊΠ°ΠΊ Π² ΡΠ°ΠΌΠΎΠΌ Lucene ΡΠ°ΠΊ ΠΈ Π² ΠΏΡΠΎΠ³ΡΠ°ΠΌΠΌΠΈΡΠΎΠ²Π°Π½ΠΈΠΈ Π² ΡΠ΅Π»ΠΎΠΌ !
UI ΠΠΠΠ
ΠΠ»Ρ Π»ΡΡΡΠ΅Π³ΠΎ ΠΏΠΎΠ½ΠΈΠΌΠ°Π½ΠΈΡ ΠΈΠ·Π»ΠΎΠΆΠ΅Π½Π½ΠΎΠ³ΠΎ ΠΌΠ°ΡΠ΅ΡΠΈΠ°Π»Π° Π½Π°Π±ΡΠΎΡΠ°Π» ΠΏΡΠΎΡΡΠ΅Π½ΡΠΊΠΈΠΉ UI (ΠΈΡΡ
ΠΎΠ΄Π½ΠΈΠΊΠΈ) Π½Π° ReactJS. ΠΠ»Ρ ΡΠ°Π±ΠΎΡΡ Π΄Π΅ΠΌΠΎ ΠΈΠ· Π±ΡΠ°ΡΠ·Π΅ΡΠ° Π½ΡΠΆΠ½ΠΎ Π½Π° ΡΠ΅ΡΠ²Π΅ΡΠ΅ ElasticSearch, ΠΊΠΎΡΠΎΡΡΠΉ ΠΌΡ ΡΠ΅ΠΉΡΠ°Ρ Π½Π°ΡΡΡΠΎΠΈΠΌ, ΡΠ°Π·ΡΠ΅ΡΠΈΡΡ http.cors
Π½Π°ΠΏΡΠΈΠΌΠ΅Ρ allow-origin: /https?:\/\/proiot\.ru/
, Π»ΠΈΠ±ΠΎ ΠΏΡΠΎΡΡΠΎ Π·Π²ΡΠ·Π΄ΠΎΡΠΊΠ° *
- ΡΠ°Π·ΡΠ΅ΡΠΈΡΡ ΠΎΡΠΎΠ²ΡΡΠ΄Ρ.
TL;DR
ΠΡΠ΅Π΄ΠΏΠΎΠ»Π°Π³Π°Π΅ΡΡΡ ΡΡΠΎ ElasticSearch ΡΠΆΠ΅ ΡΡΡΠ°Π½ΠΎΠ²Π»Π΅Π½ ΠΈ Π½Π°ΡΡΡΠΎΠ΅Π½:
~$ curl -XGET localhost:9200
# response
{
"name" : "J2",
"cluster_name" : "docker-cluster",
"version" : {
"number" : "2.3.3",
"build_hash" : "218bdf10790eef486ff2c41a3df5cfa32dadcfde",
"build_timestamp" : "2016-05-17T15:40:04Z",
"build_snapshot" : false,
"lucene_version" : "5.5.0"
},
"tagline" : "You Know, for Search"
}
ΠΠΎΡΡΠ°ΡΠΎΡΠ½ΠΎ ΠΏΡΠΎΡΡΠΎ ΠΏΡΠΎΠΈΠ½Π΄Π΅ΠΊΡΠΈΡΠΎΠ²Π°ΡΡ ΡΠΎΠ΄Π΅ΡΠΆΠΈΠΌΠΎΠ΅ Π΄Π°ΠΌΠΏΠ° Top.bulk.json.xz:
# field mapping for suggest, aggregation
# curl -XDELETE 'localhost:9200/kinopoisk?pretty'
~$ curl -XPUT 'localhost:9200/kinopoisk?pretty' -d '{
"mappings": {
"film" : {
"properties" : {
"suggest" : {
"type" : "completion",
"analyzer": "standard"
},
"category": {
"type": "string",
"fields": {
"raw": {
"type": "string",
"index": "not_analyzed"
}
}
},
"directed": {
"type": "string",
"fields": {
"raw": {
"type": "string",
"index": "not_analyzed"
}
}
},
"starring": {
"type": "string",
"fields": {
"raw": {
"type": "string",
"index": "not_analyzed"
}
}
}
}
}
}
}'
# index 14992 docs(verify: echo `xzcat Top.bulk.json.xz | wc -l` / 2 | bc -l)
~$ xzcat Top.bulk.json.xz | curl -XPOST localhost:9200/_bulk --data-binary @-
ΠΠΎΠ»Ρ category, directed, starring Π² ΡΠ΅ΡΠΌΠΈΠ½ΠΎΠ»ΠΎΠ³ΠΈΠΈ Elastic ΡΠ²Π»ΡΡΡΡΡ multi-field, Π² Π½Π°ΡΠ΅ΠΌ ΡΠ»ΡΡΠ°Π΅ ΠΎΠ½ΠΈ Π΄ΠΎΠΏΠΎΠ»Π½ΠΈΡΠ΅Π»ΡΠ½ΠΎ Ρ
ΡΠ°Π½ΡΡ ΠΎΡΠΈΠ³ΠΈΠ½Π°Π»ΡΠ½ΡΠ΅ Π·Π½Π°ΡΠ΅Π½ΠΈΡ ΡΡΠΎ ΠΏΠΎΠ·Π²ΠΎΠ»ΠΈΡ Π°Π³ΡΠ΅Π³ΠΈΡΠΎΠ²Π°ΡΡ ΠΈ ΡΠΈΠ»ΡΡΡΠΎΠ²Π°ΡΡ Π²ΡΠ΄Π°ΡΡ ΠΏΠΎ ΡΡΡΠΎΠ³ΠΎΠΌΡ ΡΠΎΠ²ΠΏΠ°Π΄Π΅Π½ΠΈΡ - Π½Π°ΠΏΡΠΈΠΌΠ΅Ρ ΡΠ΅ΠΆΠΈΡΡΡΡ "ΠΠ³ΠΎΡΡ ΠΠ°ΡΠ»Π΅Π½Π½ΠΈΠΊΠΎΠ²" Π²ΠΌΠ΅ΡΡΠΎ "ΠΠ³ΠΎΡΡ" ΠΈ "ΠΠ°ΡΠ»Π΅Π½Π½ΠΈΠΊΠΎΠ²" ΠΏΠΎ ΠΎΡΠ΄Π΅Π»ΡΠ½ΠΎΡΡΠΈ. ΠΠΎΡΠ»Π΅ ΠΈΠ½Π΄Π΅ΠΊΡΠ°ΡΠΈΠΈ ΡΠΎΠ±ΡΡΠ²Π΅Π½Π½ΠΎ ΠΌΠΎΠΆΠ½ΠΎ ΠΎΡΡΡΠ΅ΡΡΠ²Π»ΡΡΡ ΠΏΠΎΠΈΡΠΊ Ρ ΠΏΠΎΠ΄ΡΠ²Π΅ΡΠΊΠΎΠΉ, ΡΠΎΡΡΠΈΡΠΎΠ²ΠΊΠΎΠΉ, Π°Π³ΡΠ΅Π³Π°ΡΠΈΠ΅ΠΉ ΠΈ ΡΠΈΠ»ΡΡΡΠ°ΡΠΈΠ΅ΠΉ, ΠΊ ΠΎΡΠΎΠ·Π½Π°Π½ΠΈΡ ΠΊΠΎΡΠΎΡΠΎΠ³ΠΎ Π±ΡΠ»ΠΎ Π±Ρ Π·Π΄ΠΎΡΠΎΠ²ΠΎ ΠΏΠΎΠ΄ΠΎΠΉΡΠΈ ΠΏΠΎ ΠΎΠΊΠΎΠ½ΡΠ°Π½ΠΈΠΈ Π΄Π°Π½Π½ΠΎΠ³ΠΎ ΠΌΠ°ΡΠ΅ΡΠΈΠ°Π»Π°:
~$ curl -XGET 'localhost:9200/kinopoisk/film/_search?pretty' -d ' {
"fields" : ["rate"],
"query" : {
"bool": {
"must": [
{
"query_string" : {
"query": "ΡΠ΅ΡΠ»ΠΎΠΊ",
"fields": [ "name", "description" ],
"default_operator": "and"
}
}
],
"filter": [
{
"match": {
"directed.raw": "ΠΠ³ΠΎΡΡ ΠΠ°ΡΠ»Π΅Π½Π½ΠΈΠΊΠΎΠ²"
}
},
{
"bool": {
"must": [
{
"match": {
"category.raw": "Π΄Π΅ΡΠ΅ΠΊΡΠΈΠ²"
}
},
{
"match": {
"category.raw": "ΠΊΡΠΈΠΌΠΈΠ½Π°Π»"
}
}
]
}
},
{
"range" : {
"date" : {
"gte" : "1980",
"lt" : "1980||+1y",
"format": "yyyy-MM||yyyy"
}
}
}
]
}
},
"highlight" : {
"pre_tags" : ["[mazko.github.io]"],
"post_tags" : ["[/mazko.github.io]"],
"fields" : {
"name" : {"fragment_size" : 22, "number_of_fragments" : 1},
"description" : {"fragment_size" : 22, "number_of_fragments" : 1}
}
},
"sort" : [
{"rate" : {"order" : "desc"} }
],
"aggs": {
"years": {
"date_histogram": {
"field": "date",
"interval": "year",
"min_doc_count": 1,
"order" : { "_count" : "desc" }
},
"aggs": {
"months": {
"date_histogram": {
"field": "date",
"interval": "month",
"min_doc_count": 1,
"order" : { "_count" : "desc" }
}
}
}
},
"categories" : {
"terms" : { "field" : "category.raw", "size": 0 }
},
"directors" : {
"terms" : { "field" : "directed.raw", "size": 0 }
},
"stars" : {
"terms" : { "field" : "starring.raw", "size": 0 }
}
}
}'
# response
{
"took" : 3117,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 5,
"max_score" : null,
"hits" : [ {
"_index" : "kinopoisk",
"_type" : "film",
"_id" : "77269",
"_score" : null,
"fields" : {
"rate" : [ 8.415 ]
},
"highlight" : {
"name" : [ "[mazko.github.io]Π¨Π΅ΡΠ»ΠΎΠΊ[/mazko.github.io] Π₯ΠΎΠ»ΠΌΡ ΠΈ Π΄ΠΎΠΊΡΠΎΡ" ],
"description" : [ " [mazko.github.io]Π¨Π΅ΡΠ»ΠΎΠΊ[/mazko.github.io] Π₯ΠΎΠ»ΠΌΡ. ΠΡΠΎ" ]
},
"sort" : [ 8.415 ]
}, {
"_index" : "kinopoisk",
"_type" : "film",
"_id" : "354799",
"_score" : null,
"fields" : {
"rate" : [ 8.313 ]
},
"highlight" : {
"name" : [ "[mazko.github.io]Π¨Π΅ΡΠ»ΠΎΠΊ[/mazko.github.io] Π₯ΠΎΠ»ΠΌΡ ΠΈ Π΄ΠΎΠΊΡΠΎΡ" ],
"description" : [ "[mazko.github.io]Π¨Π΅ΡΠ»ΠΎΠΊ[/mazko.github.io] Π₯ΠΎΠ»ΠΌΡ Π²ΡΡΡΠΏΠΈΠ»" ]
},
"sort" : [ 8.313 ]
}, {
"_index" : "kinopoisk",
"_type" : "film",
"_id" : "77265",
"_score" : null,
"fields" : {
"rate" : [ 8.297 ]
},
"highlight" : {
"name" : [ "[mazko.github.io]Π¨Π΅ΡΠ»ΠΎΠΊ[/mazko.github.io] Π₯ΠΎΠ»ΠΌΡ ΠΈ Π΄ΠΎΠΊΡΠΎΡ" ],
"description" : [ ". ΠΠΎΒ Π²ΡΠΎΡΠΎΠΉΒ β [mazko.github.io]Π¨Π΅ΡΠ»ΠΎΠΊ[/mazko.github.io]" ]
},
"sort" : [ 8.297 ]
}, {
"_index" : "kinopoisk",
"_type" : "film",
"_id" : "368937",
"_score" : null,
"fields" : {
"rate" : [ 8.269 ]
},
"highlight" : {
"description" : [ " Π²ΠΎΠ΄ΠΎΠΏΠ°Π΄Π°. [mazko.github.io]Π¨Π΅ΡΠ»ΠΎΠΊ[/mazko.github.io] Π₯ΠΎΠ»ΠΌΡ" ]
},
"sort" : [ 8.269 ]
}, {
"_index" : "kinopoisk",
"_type" : "film",
"_id" : "368936",
"_score" : null,
"fields" : {
"rate" : [ 8.248 ]
},
"highlight" : {
"name" : [ "[mazko.github.io]Π¨Π΅ΡΠ»ΠΎΠΊ[/mazko.github.io] Π₯ΠΎΠ»ΠΌΡ ΠΈ Π΄ΠΎΠΊΡΠΎΡ" ],
"description" : [ "Β ΡΠ³ΡΠΎΠ·ΠΎΠΉ. [mazko.github.io]Π¨Π΅ΡΠ»ΠΎΠΊ[/mazko.github.io] Π₯ΠΎΠ»ΠΌΡ" ]
},
"sort" : [ 8.248 ]
} ]
},
"aggregations" : {
"directors" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [ {
"key" : "ΠΠ³ΠΎΡΡ ΠΠ°ΡΠ»Π΅Π½Π½ΠΈΠΊΠΎΠ²",
"doc_count" : 5
} ]
},
"categories" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [ {
"key" : "Π΄Π΅ΡΠ΅ΠΊΡΠΈΠ²",
"doc_count" : 5
}, {
"key" : "ΠΊΡΠΈΠΌΠΈΠ½Π°Π»",
"doc_count" : 5
} ]
},
"stars" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [ {
"key" : "ΠΠ°ΡΠΈΠ»ΠΈΠΉ ΠΠΈΠ²Π°Π½ΠΎΠ²",
"doc_count" : 5
}, {
"key" : "ΠΠΈΡΠ°Π»ΠΈΠΉ Π‘ΠΎΠ»ΠΎΠΌΠΈΠ½",
"doc_count" : 5
}, {
"key" : "Π ΠΈΠ½Π° ΠΠ΅Π»Π΅Π½Π°Ρ",
"doc_count" : 5
}, {
"key" : "ΠΠΎΡΠΈΡΠ»Π°Π² ΠΡΠΎΠ½Π΄ΡΠΊΠΎΠ²",
"doc_count" : 4
}, {
"key" : "ΠΠΎΡΠΈΡ ΠΠ»ΡΠ΅Π²",
"doc_count" : 3
}, {
"key" : "ΠΠ»Π΅ΠΊΡΠ°Π½Π΄Ρ ΠΠ°Ρ
Π°ΡΠΎΠ²",
"doc_count" : 2
}, {
"key" : "ΠΠ»Π΅ΠΊΡΠ΅ΠΉ ΠΠΎΠΆΠ΅Π²Π½ΠΈΠΊΠΎΠ²",
"doc_count" : 2
}, {
"key" : "ΠΠ°Π»Π΅Π½ΡΠΈΠ½Π° ΠΠ°Π½ΠΈΠ½Π°",
"doc_count" : 2
}, {
"key" : "ΠΠΈΠΊΡΠΎΡ ΠΠ²Π³ΡΠ°ΡΠΎΠ²",
"doc_count" : 2
}, {
"key" : "ΠΠ³ΠΎΡΡ ΠΠΌΠΈΡΡΠΈΠ΅Π²",
"doc_count" : 2
}, {
"key" : "ΠΠ³ΠΎΡΡ ΠΡΠΈΠΌΠΎΠ²",
"doc_count" : 2
}, {
"key" : "ΠΠΈΠΊΠΎΠ»Π°ΠΉ ΠΡΡΠΊΠΎΠ²",
"doc_count" : 2
}, {
"key" : "ΠΠ΄ΠΎΠ»ΡΡ ΠΠ»ΡΠΈΠ½",
"doc_count" : 1
}, {
"key" : "ΠΠ½Π°ΡΠΎΠ»ΠΈΠΉ ΠΠΎΠ΄ΡΠΈΠ²Π°Π»ΠΎΠ²",
"doc_count" : 1
}, {
"key" : "ΠΠΎΡΠΈΡ Π ΡΠΆΡΡ
ΠΈΠ½",
"doc_count" : 1
}, {
"key" : "ΠΠΈΠΊΡΠΎΡ ΠΡΠΈΡΡΠΎΠ²",
"doc_count" : 1
}, {
"key" : "ΠΠΈΡΠ°Π»ΠΈΠΉ ΠΠ°Π³Π°Π½ΠΎΠ²",
"doc_count" : 1
}, {
"key" : "ΠΠ΅Π½Π½Π°Π΄ΠΈΠΉ ΠΠΎΠ³Π°ΡΡΠ²",
"doc_count" : 1
}, {
"key" : "ΠΠ³Π½Π°Ρ ΠΠ΅ΠΉΡΠ΅Ρ",
"doc_count" : 1
}, {
"key" : "ΠΠ°ΡΠ΅ΡΠΈΠ½Π° Π¨Π΅Π»Π»",
"doc_count" : 1
}, {
"key" : "ΠΠ°ΡΠΈΡ Π‘ΠΎΠ»ΠΎΠΌΠΈΠ½Π°",
"doc_count" : 1
}, {
"key" : "ΠΠΈΠΊΠΎΠ»Π°ΠΉ ΠΠ°ΡΠ°ΡΠ΅Π½ΡΠΎΠ²",
"doc_count" : 1
}, {
"key" : "Π‘Π²Π΅ΡΠ»Π°Π½Π° ΠΡΡΡΠΊΠΎΠ²Π°",
"doc_count" : 1
}, {
"key" : "Π€Π΅Π΄ΠΎΡ ΠΠ΄ΠΈΠ½ΠΎΠΊΠΎΠ²",
"doc_count" : 1
} ]
},
"years" : {
"buckets" : [ {
"key_as_string" : "1980-01-01T00:00:00.000Z",
"key" : 315532800000,
"doc_count" : 5,
"months" : {
"buckets" : [ {
"key_as_string" : "1980-01-01T00:00:00.000Z",
"key" : 315532800000,
"doc_count" : 3
}, {
"key_as_string" : "1980-03-01T00:00:00.000Z",
"key" : 320716800000,
"doc_count" : 2
} ]
}
} ]
}
}
}
Π Π·Π°ΠΏΡΠΎΡΠ΅ ΠΌΡ ΠΈΡΠΊΠ°Π»ΠΈ ΡΡΡΠΎΠΊΡ ΡΠ΅ΡΠ»ΠΎΠΊ ΠΏΠΎ ΠΏΠΎΠ»ΡΠΌ name ΠΈ description, ΠΈΡΠΊΠ»ΡΡΠΈΠ»ΠΈ Π²ΡΠ΅ ΡΠΈΠ»ΡΠΌΡ ΠΊΡΠΎΠΌΠ΅ ΡΠ΅ΠΆΠΈΡΡΡΡΠ° "ΠΠ³ΠΎΡΡ ΠΠ°ΡΠ»Π΅Π½Π½ΠΈΠΊΠΎΠ²", ΠΆΠ°Π½ΡΡ Π΄ΠΎΠΆΠ½Ρ Π±ΡΡΡ ΡΠΎΠ»ΡΠΊΠΎ ΠΈ Π΄Π΅ΡΠ΅ΠΊΡΠΈΠ² ΠΈ ΠΊΡΠΈΠΌΠΈΠ½Π°Π», ΡΠΎΠ»ΡΠΊΠΎ 1980 Π³ΠΎΠ΄. Π‘ΠΎΡΡΠΈΡΠΎΠ²ΠΊΠ° Π½Π°ΠΉΠ΄Π΅Π½Π½ΡΡ
ΡΠ΅Π·ΡΠ»ΡΡΠ°ΡΠΎΠ² ΠΏΠΎ ΠΏΠΎΠ»Ρ rate. ΠΡΠΎΡΡΠ°Ρ Π°Π³ΡΠ΅Π³Π°ΡΠΈΡ ΠΏΠΎ ΠΏΠΎΠ»ΡΠΌ category, directed ΠΈ starring. ΠΠ»ΠΎΠΆΠ΅Π½Π½Π°Ρ Π°Π³ΡΠ΅Π³Π°ΡΠΈΡ ΠΏΠΎ Π΄Π°ΡΠ΅ - Π³ΠΎΠ΄Ρ ΠΈ Π² Π½ΠΈΡ
ΠΌΠ΅ΡΡΡΡ. ΠΠΎ ΠΎΠ±ΠΎ Π²ΡΡΠΌ ΠΏΠΎ ΠΏΠΎΡΡΠ΄ΠΊΡ :)
Π£Π‘Π’ΠΠΠΠΠΠ Π ΠΠΠ‘Π’Π ΠΠΠΠ ELASTICSEARCH
ΠΡΠ΅Π΄ΠΏΠΎΠ»Π°Π³Π°Π΅ΡΡΡ ΡΡΠΎ Π² ΡΠΈΡΡΠ΅ΠΌΠ΅ ΡΠΆΠ΅ ΡΡΡΠ°Π½ΠΎΠ²Π»Π΅Π½ Docker:
~$ docker -v
Docker version 1.11.2, build b9f10c9
~$ docker pull ubuntu && docker run -it ubuntu
root@d1b1c0c6bddc:/# cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04 LTS"
root@d1b1c0c6bddc:/# apt update && apt -y upgrade && \
apt -y install software-properties-common command-not-found \
man-db openjdk-8-jdk wget curl net-tools
root@d1b1c0c6bddc:/# wget -qO - https://packages.elastic.co/GPG-KEY-elasticsearch | apt-key add -
root@d1b1c0c6bddc:/# echo "deb https://packages.elastic.co/elasticsearch/2.x/debian stable main" |\
tee -a /etc/apt/sources.list.d/elasticsearch-2.x.list
root@d1b1c0c6bddc:/# apt -y install apt-transport-https && apt update && apt install -y elasticsearch
root@d1b1c0c6bddc:/# cd /usr/share/elasticsearch/
root@d1b1c0c6bddc:/# mkdir config/ && chown elasticsearch:elasticsearch config/
root@d1b1c0c6bddc:/# mkdir logs/ && chown elasticsearch:elasticsearch logs/
root@d1b1c0c6bddc:/# mkdir data/ && chown elasticsearch:elasticsearch data/
root@d1b1c0c6bddc:/# cat <<EOT > /usr/share/elasticsearch/config/logging.yml
rootLogger: TRACE,console
appender:
console:
type: console
layout:
type: consolePattern
conversionPattern: "[%d{ISO8601}][%-5p][%-25c] %m%n"
EOT
root@d1b1c0c6bddc:/# cat <<EOT > /usr/share/elasticsearch/config/elasticsearch.yml
cluster.name: "docker-cluster"
network.host: 0.0.0.0
http.max_content_length: 333mb
http.cors:
enabled: true
allow-origin: /https?:\/\/localhost(:[0-9]+)?/
allow-methods: OPTIONS, HEAD, GET, POST, PUT, DELETE
allow-headers: X-Requested-With,X-Auth-Token,Content-Type, Content-Length
EOT
root@d1b1c0c6bddc:/# exit
Π Π½Π°ΡΡΡΠΎΠΉΠΊΠ°Ρ
ΠΌΡ Π΄ΠΎΠ±Π°Π²ΠΈΠ»ΠΈ ΠΏΠΎΠ΄Π΄Π΅ΡΠΆΠΊΡ http.cors
ΡΡΠΎΠ±Ρ Ρ elastic ΠΌΠΎΠΆΠ½ΠΎ Π±ΡΠ»ΠΎ ΡΠ°Π±ΠΎΡΠ°ΡΡ Π½Π°ΠΏΡΡΠΌΡΡ ΠΈΠ· Π±ΡΠ°ΡΠ·Π΅ΡΠ°. ΠΠ° ΡΡΠΎΠΌ ΡΡΡΠ°Π½ΠΎΠ²ΠΊΠ° ΠΈ Π½Π°ΡΡΡΠΎΠΉΠΊΠ° Π·Π°Π²Π΅ΡΡΠ΅Π½Π° - ΠΎΡΡΠ°Π»ΠΎΡΡ Π·Π°ΡΠΈΠΊΡΠΈΡΠΎΠ²Π°ΡΡ ΠΈΠ·ΠΌΠ΅Π½Π΅Π½ΠΈΡ ΠΈ Π·Π°ΠΏΡΡΡΠΈΡΡ ΠΎΠ±ΡΠ°Π·:
~$ docker commit d1b1c0c6bddc elastic
~$ docker rm d1b1c0c6bddc
~$ docker run --rm -it -u elasticsearch -p 9200:9200 elastic \
/usr/share/elasticsearch/bin/elasticsearch
ΠΡΠΎΠ²Π΅ΡΠΊΠ° http.cors
:
~$ curl -I -H 'Origin: http://localhost:8080' 'http://localhost:9200/'
# response
HTTP/1.1 200 OK
Access-Control-Allow-Origin: http://localhost:8080
Content-Type: text/plain; charset=UTF-8
Content-Length: 0
~$ curl -I -H 'Origin: http://some.hacker.com' 'http://localhost:9200/'
# response
HTTP/1.1 403 Forbidden
Π Π½Π°ΡΡΠΎΠΉΠΊΠ°Ρ
http.cors
Π½Π΅Ρ ΡΠΏΠΎΠΌΠΈΠ½Π°Π½ΠΈΠΉ ΠΎ some.hacker.com ΠΏΠΎΡΡΠΎΠΌΡ ΡΠΏΡΠ°Π²Π΅Π΄Π»ΠΈΠ²ΠΎ 403. ΠΠ°ΠΊΠΎΠ½Π΅Ρ Π΅ΡΠ»ΠΈ ΠΌΡ Ρ
ΠΎΡΠΈΠΌ ΡΡΠΎΠ±Ρ Π΄Π°Π½Π½ΡΠ΅ ΡΠ°Π±ΠΎΡΡ ΠΎΠ±ΡΠ°Π·Π° elastic ΡΠΎΡ
ΡΠ°Π½ΡΠ»ΠΈΡΡ ΠΏΠΎΡΠ»Π΅ Π΅Π³ΠΎ ΠΏΠ΅ΡΠ΅Π·Π°ΠΏΡΡΠΊΠ°:
~$ docker volume create --name elastic-data
# user: elasticsearch, port forward 9200, image: elastic, volume: elastic-data
~$ docker run --rm -it -u elasticsearch -p 9200:9200 \
-v elastic-data:/usr/share/elasticsearch/data elastic \
/usr/share/elasticsearch/bin/elasticsearch
Π‘ Docker Π²ΡΡ.
REST API
ΠΠ½Π΄Π΅ΠΊΡΠ°ΡΠΈΡ:
~$ curl -XPOST 'localhost:9200/kinopoisk/film?pretty' -d {'
"id": 409640,
"name": "ΠΠ°ΡΠ» (ΡΠ΅ΡΠΈΠ°Π» 2009 β ...)",
"description": "ΠΠ½Π°ΠΊΠΎΠΌΡΡΠ΅ΡΡ, Π ΠΈΡΠ°ΡΠ΄ ΠΠ°ΡΠ»Β βΒ ΡΡΠΏΠ΅ΡΠ½ΡΠΉ ΠΏΠΈΡΠ°ΡΠ΅Π»Ρ Π΄Π΅ΡΠ΅ΠΊΡΠΈΠ²Π½ΠΎΠ³ΠΎ ΠΆΠ°Π½ΡΠ°...",
"date": "2009-03-08T22:00:00.000Z",
"rate": 8.042,
"starring": [
"ΠΡΠΉΡΠ°Π½ Π€ΠΈΠ»Π»ΠΈΠΎΠ½",
"Π‘ΡΠ°Π½Π° ΠΠ°ΡΠΈΠΊ",
"Π‘ΡΡΠ·ΡΠ½ Π‘Π°Π»Π»ΠΈΠ²Π°Π½",
"ΠΠΆΠΎΠ½ Π£ΡΡΡΠ°Ρ",
"Π¨Π΅ΠΉΠΌΡΡ ΠΠ΅Π²Π΅Ρ",
"ΠΠΎΠ»Π»ΠΈ Π. ΠΡΠΈΠ½Π½",
"Π’Π°ΠΌΠ°Π»Π° ΠΠΆΠΎΠ½Ρ",
"ΠΠ΅Π½Π½ΠΈ ΠΠΆΠΎΠ½ΡΠΎΠ½",
"Π ΡΠ±Π΅Π½ Π‘Π°Π½ΡΡΡΠ³ΠΎ-Π₯Π°Π΄ΡΠΎΠ½",
"ΠΠ°ΠΉΡ Π‘ΡΠΎΡΠ½"
],
"category": [
"Π΄ΡΠ°ΠΌΠ°",
"ΠΌΠ΅Π»ΠΎΠ΄ΡΠ°ΠΌΠ°",
"ΠΊΠΎΠΌΠ΅Π΄ΠΈΡ",
"ΠΊΡΠΈΠΌΠΈΠ½Π°Π»",
"Π΄Π΅ΡΠ΅ΠΊΡΠΈΠ²"
],
"directed": [
"Π ΠΎΠ± ΠΠΎΡΠΌΠ΅Π½",
"ΠΠΆΠΎΠ½ Π’Π΅ΡΠ»Π΅ΡΠΊΠΈ",
"ΠΠΈΠ»Π» Π ΠΎΡ"
]
}'
# response
{
"_index" : "kinopoisk",
"_type" : "film",
"_id" : "AVWHlznJTgOouHAvlXph",
"_version" : 1,
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"created" : true
}
~$ curl -XPOST 'localhost:9200/kinopoisk/film?pretty' -d {'
"id": 153013,
"name": "ΠΠ²Π΅Π·Π΄Π½ΡΠΉ ΠΊΡΠ΅ΠΉΡΠ΅Ρ ΠΠ°Π»Π°ΠΊΡΠΈΠΊΠ° (ΡΠ΅ΡΠΈΠ°Π» 2004 β 2009)",
"description": "Π§ΡΠ΄ΠΎΠΌ ΡΡΠ΅Π»Π΅Π² ΠΏΠΎΡΠ»Π΅ Π½Π°ΠΏΠ°Π΄Π΅Π½ΠΈΡ Π‘Π°ΠΉΠ»ΠΎΠ½ΠΎΠ²...",
"date": "2004-10-17T21:00:00.000Z",
"rate": 7.943,
"starring": [
"ΠΠ΄Π²Π°ΡΠ΄ ΠΠΆΠ΅ΠΉΠΌΡ ΠΠ»ΠΌΠΎΡ",
"ΠΡΡΠΈ ΠΠ°ΠΊΠΠΎΠ½Π½Π΅Π»Π»",
"ΠΠΆΠ΅ΠΉΠΌΠΈ ΠΠ°ΠΌΠ±Π΅Ρ",
"ΠΠΆΠ΅ΠΉΠΌΡ ΠΡΠ»Π»ΠΈΡ",
"Π’ΡΠΈΡΠ° Π₯Π΅Π»ΡΠ΅Ρ",
"ΠΡΠ΅ΠΉΡ ΠΠ°ΠΊ",
"ΠΡΡΠΈ Π‘Π°ΠΊΡ
ΠΎΡΡ",
"ΠΠ°ΠΉΠΊΠ» Π₯ΠΎΠ³Π°Π½",
"ΠΠ°ΡΠΎΠ½ ΠΡΠ³Π»Π°Ρ",
"Π’Π°ΠΌΠΎ ΠΠ΅Π½ΠΈΠΊΠ΅ΡΡ"
],
"category": [
"ΡΠ°Π½ΡΠ°ΡΡΠΈΠΊΠ°",
"Π±ΠΎΠ΅Π²ΠΈΠΊ",
"Π΄ΡΠ°ΠΌΠ°",
"ΠΏΡΠΈΠΊΠ»ΡΡΠ΅Π½ΠΈΡ"
],
"directed": [
"ΠΠ°ΠΉΠΊΠ» Π Π°ΠΉΠΌΠ΅Ρ",
"ΠΠ°ΠΉΠΊΠ» ΠΠ°Π½ΠΊΠΈΠ½",
"Π ΠΎΠ΄ Π₯Π°ΡΠ΄ΠΈ"
]
}'
# response
{
"_index" : "kinopoisk",
"_type" : "film",
"_id" : "AVWHnN7ATgOouHAvlXpl",
"_version" : 1,
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"created" : true
}
~$ curl -XGET 'localhost:9200/kinopoisk/_mapping?pretty'
# response
{
"kinopoisk" : {
"mappings" : {
"film" : {
"properties" : {
"category" : {
"type" : "string"
},
"date" : {
"type" : "date",
"format" : "strict_date_optional_time||epoch_millis"
},
"description" : {
"type" : "string"
},
"directed" : {
"type" : "string"
},
"id" : {
"type" : "long"
},
"name" : {
"type" : "string"
},
"rate" : {
"type" : "double"
},
"starring" : {
"type" : "string"
}
}
}
}
}
}
ElasticSearch Π°Π²ΡΠΎΠΌΠ°ΡΠΈΡΠ΅ΡΠΊΠΈ ΠΈ Π΄Π°ΠΆΠ΅ ΠΏΡΠ°Π²ΠΈΠ»ΡΠ½ΠΎ ΡΠ°ΡΠΏΠΎΠ·Π½Π°Π» ΡΠΈΠΏΡ Π΄Π°Π½Π½ΡΡ
Π΄Π»Ρ Π²ΡΠ΅Ρ
ΠΏΠΎΠ»Π΅ΠΉ Π² ΠΈΠ½Π΄Π΅ΠΊΡΠ΅ ! ΠΡΠΎΡΡΠΎΠΉ ΠΏΠΎΡΡΡΠ°Π½ΠΈΡΠ½ΡΠΉ ΠΏΠΎΠΈΡΠΊ ΠΏΠΎ Π΄Π²ΡΠΌ ΠΏΠΎΠ»ΡΠΌ name ΠΈ description, Π² ΡΠ΅Π·ΡΠ»ΡΡΠ°ΡΠ°Ρ
ΠΏΠΎΠΈΡΠΊΠ° Π²ΡΠ²ΠΎΠ΄ΠΈΡΡ ΡΠΎΠ»ΡΠΊΠΎ Π·Π½Π°ΡΠ΅Π½ΠΈΡ ΠΏΠΎΠ»Π΅ΠΉ id, rate:
~$ curl -XGET 'localhost:9200/kinopoisk/film/_search?pretty' -d {'
"fields" : ["id", "rate"],
"query" : {
"query_string" : {
"query": "ΠΠ°ΡΠ»",
"fields": [ "name", "description" ],
"default_operator": "and"
}
}
}'
# response
{
"took" : 8,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 1,
"max_score" : 0.15342641,
"hits" : [ {
"_index" : "kinopoisk",
"_type" : "film",
"_id" : "AVWHmwbSTgOouHAvlXpi",
"_score" : 0.15342641,
"fields" : {
"rate" : [ 8.042 ],
"id" : [ 409640 ]
}
} ]
}
}
ΠΠΎΠΈΡΠΊ Ρ ΠΏΠΎΠ΄ΡΠ²Π΅ΡΠΊΠΎΠΉ:
~$ curl -XGET 'localhost:9200/kinopoisk/film/_search?pretty' -d {'
"fields" : ["id", "rate"],
"query" : {
"query_string" : {
"query": "ΡΠ°ΠΉΠ»ΠΎΠ½*",
"fields": [ "name", "description" ],
"default_operator": "and"
}
},
"highlight" : {
"pre_tags" : ["[mazko.github.io]"],
"post_tags" : ["[/mazko.github.io]"],
"fields" : {
"name" : {"fragment_size" : 22, "number_of_fragments" : 1},
"description" : {"fragment_size" : 22, "number_of_fragments" : 1}
}
}
}'
# response
{
"took" : 218,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 1,
"max_score" : 1.0,
"hits" : [ {
"_index" : "kinopoisk",
"_type" : "film",
"_id" : "AVWHnN7ATgOouHAvlXpl",
"_score" : 1.0,
"fields" : {
"rate" : [ 7.943 ],
"id" : [ 153013 ]
},
"highlight" : {
"description" : [ " Π½Π°ΠΏΠ°Π΄Π΅Π½ΠΈΡ [mazko.github.io]Π‘Π°ΠΉΠ»ΠΎΠ½ΠΎΠ²[/mazko.github.io]..." ]
}
} ]
}
}
Π‘Π°ΠΌΠΎΠ΅ Π²ΡΠ΅ΠΌΡ Π΄Π»Ρ ΡΠ΅Π°Π»ΡΠ½ΡΡ
Π΄Π°Π½Π½ΡΡ
:
~: curl -XDELETE 'localhost:9200/kinopoisk?pretty'
~: time python3 -c \
'import sys, json; [print(json.dumps(i, ensure_ascii=False)) for i in json.load(sys.stdin)]' \
< Top.json | xargs -d '\n' -n1 curl -XPOST 'localhost:9200/kinopoisk/film/' -d
# time
real 18m52.728s
user 1m36.896s
sys 0m36.216s
ΠΡΠΎΡΠ΅ΡΡ ΠΈΠ½Π΄Π΅ΠΊΡΠ°ΡΠΈΠΈ ΠΌΠΎΠΆΠ½ΠΎ Π·Π½Π°ΡΠΈΡΠ΅Π»ΡΠ½ΠΎ ΡΡΠΊΠΎΡΠΈΡΡ ΠΈΡΠΏΠΎΠ»ΡΠ·ΡΡ Bulk API:
~: curl -XDELETE 'localhost:9200/kinopoisk?pretty'
~: time python3 -c \
'import sys, json; [print(json.dumps({ "index" : { "_index" : "kinopoisk", "_type" : "film" } }),
"\n", json.dumps(i, ensure_ascii=False)) for i in json.load(sys.stdin)]' \
< Top.json | curl -XPOST localhost:9200/_bulk --data-binary @-
# time
real 0m14.450s
user 0m1.044s
sys 0m0.196s
ΠΠ΅ΠΌΠ½ΠΎΠ³ΠΎ ΠΏΠΎΠ»Π΅Π·Π½ΠΎΠΉ ΡΡΠ°ΡΠΈΡΡΠΈΠΊΠΈ ΠΎΠ± ΠΈΠ½Π΄Π΅ΠΊΡΠ΅:
~: curl -XGET 'localhost:9200/kinopoisk/_count?pretty'
# response
{
"count" : 14999,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
}
}
~: curl -XGET 'localhost:9200/_cat/indices'
# response
yellow open kinopoisk 5 1 14999 0 39.1mb 39.1mb
Suggest Π² ElasticSearch Π΄ΠΎΠ²ΠΎΠ»ΡΠ½ΠΎ ΡΡΡΠ°Π½Π½ΡΠΉ Π»ΠΈΠ±ΠΎ ΠΏΠ»ΠΎΡ
ΠΎ ΠΎΠΏΠΈΡΠ°Π½Π½ΡΠΉ:
~: curl -XDELETE 'localhost:9200/kinopoisk?pretty'
~: curl -XPUT 'localhost:9200/kinopoisk?pretty' -d '{
"settings": {
"analysis": {
"filter": {
"shingle_filter": {
"type": "shingle",
"max_shingle_size": "5",
"min_shingle_size": "2",
"output_unigrams":"true"
}
},
"analyzer": {
"pre_suggest_analyzer": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"lowercase",
"shingle_filter"
]
}
}
}
}
}'
~: curl -XGET 'localhost:9200/kinopoisk/_analyze?pretty' -d '{
"analyzer": "pre_suggest_analyzer",
"text": ["ΡΠ°Π· Π΄Π²Π°", "ΡΠ°Π·"]
}'
#response
{
"tokens" : [ {
"token" : "ΡΠ°Π·",
"start_offset" : 0,
"end_offset" : 3,
"type" : "<ALPHANUM>",
"position" : 0
}, {
"token" : "ΡΠ°Π· Π΄Π²Π°",
"start_offset" : 0,
"end_offset" : 7,
"type" : "shingle",
"position" : 0
}, {
"token" : "Π΄Π²Π°",
"start_offset" : 4,
"end_offset" : 7,
"type" : "<ALPHANUM>",
"position" : 1
}, {
"token" : "ΡΠ°Π·",
"start_offset" : 8,
"end_offset" : 11,
"type" : "<ALPHANUM>",
"position" : 102
} ]
}
ΠΡΡ
ΠΎΠ΄Ρ ΠΈΠ· Π΄ΠΎΠΊΡΠΌΠ΅Π½ΡΠ°ΡΠΈΠΈ Π½Π΅ΡΠΎΠ²ΡΠ΅ΠΌ ΠΏΠΎΠ½ΡΡΠ½ΠΎ ΠΊΠ°ΠΊ Π² ΠΏΡΠΎΡΠ΅ΡΡΠ΅ ΠΈΠ½Π΄Π΅ΠΊΡΠ°ΡΠΈΠΈ ΡΠ΄Π΅Π»Π°ΡΡ ΡΠ°ΠΊΡΡ ΡΡΡΠΊΡ Π°Π²ΡΠΎΠΌΠ°ΡΠΈΡΠ΅ΡΠΊΠΎΠΉ Π±Π΅Π· ΠΈΠ·Π±ΡΡΠΎΡΠ½ΡΡ
HTTP Π·Π°ΠΏΡΠΎΡΠΎΠ² ΠΊ localhost:9200/kinopoisk/_analyze:
~: python3 -c '
import sys, json
from urllib.request import urlopen
def get_shingles(*args):
data = { "analyzer": "pre_suggest_analyzer", "text": args }
data = json.dumps(data).encode("utf8")
with urlopen("http://localhost:9200/kinopoisk/_analyze", data=data) as r:
data = json.loads(r.read().decode(r.info().get_param("charset") or "utf-8"))
tokens = map(lambda v: v["token"], data["tokens"])
tokens = filter(lambda v: len(v) > 1, tokens)
return list(set(tokens))
for film in { obj["id"]: obj for obj in json.load(sys.stdin) }.values():
film["rate"] = float(film["rate"])
film["suggest"] = { "input": get_shingles(film["name"], film["description"]) }
print(json.dumps({ "index" : { "_index" : "kinopoisk", "_type" : "film", "_id" : film["id"]} }))
print(json.dumps(film, ensure_ascii=False))
' < Top.json | xz --extreme -9 > Top.bulk.json.xz
ΠΠ½Π΄Π΅ΠΊΡ ΡΠΆΠ΅ Ρ Suggest:
~: curl -XDELETE 'localhost:9200/kinopoisk?pretty'
~: curl -XPUT 'localhost:9200/kinopoisk?pretty' -d '{
"mappings": {
"film" : {
"properties" : {
"suggest" : {
"type" : "completion",
"analyzer": "standard"
}
}
}
}
}
}'
~: xzcat Top.bulk.json.xz | curl -XPOST localhost:9200/_bulk --data-binary @-
~: curl -XGET 'localhost:9200/kinopoisk/_suggest?pretty' -d '{
"film-suggest" : {
"text" : "ΡΠ΅ΡΠ»ΠΎΠΊ ",
"completion" : {
"field" : "suggest",
"size": 5
}
}
}'
#response
{
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"film-suggest" : [ {
"text" : "ΡΠ΅ΡΠ»ΠΎΠΊ ",
"offset" : 0,
"length" : 7,
"options" : [ {
"text" : "ΡΠ΅ΡΠ»ΠΎΠΊ Ρ
ΠΎΠ»ΠΌΡ",
"score" : 3.0
}, {
"text" : "ΡΠ΅ΡΠ»ΠΎΠΊ Ρ
ΠΎΠ»ΠΌΡ ΠΈ",
"score" : 2.0
}, {
"text" : "ΡΠ΅ΡΠ»ΠΎΠΊ Ρ
ΠΎΠ»ΠΌΡ ΠΈ Π΄ΠΎΠΊΡΠΎΡ",
"score" : 2.0
}, {
"text" : "ΡΠ΅ΡΠ»ΠΎΠΊ Ρ
ΠΎΠ»ΠΌΡ ΠΈ Π΄ΠΎΠΊΡΠΎΡ Π²Π°ΡΡΠΎΠ½",
"score" : 2.0
}, {
"text" : "ΡΠ΅ΡΠ»ΠΎΠΊ ΠΌΠ»Π°Π΄ΡΠΈΠΉ",
"score" : 1.0
} ]
} ]
}
ΠΠΎΠΈΡΠΊ Ρ Π°Π³ΡΠ΅Π³Π°ΡΠΈΠ΅ΠΉ ΠΏΠΎ ΠΏΠΎΠ»Ρ starring:
~$ curl -XDELETE 'localhost:9200/kinopoisk?pretty'
~$ curl -XPUT 'localhost:9200/kinopoisk?pretty' -d '{
"mappings": {
"film" : {
"properties" : {
"starring": {
"type": "string",
"fields": {
"raw": {
"type": "string",
"index": "not_analyzed"
}
}
}
}
}
}
}'
~$ xzcat Top.bulk.json.xz | curl -XPOST localhost:9200/_bulk --data-binary @-
~$ curl -XGET 'localhost:9200/kinopoisk/film/_search?pretty' -d {'
"size": 0,
"query" : {
"query_string" : {
"query": "ΡΠ΅ΡΠ»ΠΎΠΊ",
"fields": [ "name", "description" ],
"default_operator": "and"
}
},
"aggs": {
"stars" : {
"terms" : { "field" : "starring.raw", "size": 10 }
}
}
}'
# response
{
"took" : 1103,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 16,
"max_score" : 0.0,
"hits" : [ ]
},
"aggregations" : {
"stars" : {
"doc_count_error_upper_bound" : 1,
"sum_other_doc_count" : 122,
"buckets" : [ {
"key" : "ΠΠ°ΡΠΈΠ»ΠΈΠΉ ΠΠΈΠ²Π°Π½ΠΎΠ²",
"doc_count" : 7
}, {
"key" : "ΠΠΈΡΠ°Π»ΠΈΠΉ Π‘ΠΎΠ»ΠΎΠΌΠΈΠ½",
"doc_count" : 7
}, {
"key" : "Π ΠΈΠ½Π° ΠΠ΅Π»Π΅Π½Π°Ρ",
"doc_count" : 7
}, {
"key" : "ΠΠΎΡΠΈΡΠ»Π°Π² ΠΡΠΎΠ½Π΄ΡΠΊΠΎΠ²",
"doc_count" : 6
}, {
"key" : "ΠΠΎΡΠΈΡ ΠΠ»ΡΠ΅Π²",
"doc_count" : 4
}, {
"key" : "ΠΠ»Π΅ΠΊΡΠ°Π½Π΄Ρ ΠΠ°Ρ
Π°ΡΠΎΠ²",
"doc_count" : 2
}, {
"key" : "ΠΠ»Π΅ΠΊΡΠ΅ΠΉ ΠΠΎΠΆΠ΅Π²Π½ΠΈΠΊΠΎΠ²",
"doc_count" : 2
}, {
"key" : "ΠΠ°Π»Π΅Π½ΡΠΈΠ½Π° ΠΠ°Π½ΠΈΠ½Π°",
"doc_count" : 2
}, {
"key" : "ΠΠΈΠΊΡΠΎΡ ΠΠ²Π³ΡΠ°ΡΠΎΠ²",
"doc_count" : 2
}, {
"key" : "ΠΠΆΠ΅ΡΠ°Π»ΡΠ΄ΠΈΠ½ ΠΠΆΠ΅ΠΉΠΌΡ",
"doc_count" : 2
} ]
}
}
}
There are comments.