Elasticsearch使用curl导入数据
准备数据文件
这里用了es作者的案例文件
wget https://github.com/madhusudhankonda/elasticsearch-in-action/blob/main/datasets/movie_bulk_data.json
编辑movie_bulk_data.json 文件,将第一行删除,在末尾加个回车,不然导入会报错
curl命令导入
curl -H "Content-Type: application/x-ndjson" -XPOST http://localhost:9200/_bulk --data-binary "@文件名"
curl -H "Content-Type: application/x-ndjson" -XPOST http://localhost:9200/_bulk --data-binary "@movie_bulk_data.json"
Es开发工具查询
查询movies
GET /movies/_search
返回信息,25个文档被导入了
{
"took" : 329,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 25,
"relation" : "eq"
},
"max_score" : 1.0,
"hits" : [
{
"_index" : "movies",
"_type" : "_doc",
"_id" : "1",
"_score" : 1.0,
"_source" : {
"title" : "The Shawshank Redemption",
"synopsis" : "Two imprisoned men bond over a number of years, finding solace and eventual redemption through acts of common decency.",
"actors" : [
"Tim Robbins",
"Morgan Freeman",
"Bob Gunton",
"William Sadler"
],
"director" : " Frank Darabont ",
"rating" : "9.3",
"certificate" : "R",
"genre" : "Drama "
}
},
{
"_index" : "movies",
"_type" : "_doc",
"_id" : "2",
"_score" : 1.0,
"_source" : {
"title" : "The Godfather",
"synopsis" : "An organized crime dynasty's aging patriarch transfers control of his clandestine empire to his reluctant son.",
"actors" : [
"Marlon Brando",
"Al Pacino",
"James Caan",
"Diane Keaton"
],
"director" : " Francis Ford Coppola ",
"rating" : "9.2",
"certificate" : "R",
"genre" : [
"Crime",
"Drama"
]
}
},
{
"_index" : "movies",
"_type" : "_doc",
"_id" : "3",
"_score" : 1.0,
"_source" : {
"title" : "The Dark Knight",
"synopsis" : "When the menace known as the Joker wreaks havoc and chaos on the people of Gotham, Batman must accept one of the greatest psychological and physical tests of his ability to fight injustice.",
"actors" : [
"Christian Bale",
"Heath Ledger",
"Aaron Eckhart",
"Michael Caine"
],
"director" : " Christopher Nolan ",
"rating" : "9.0",
"certificate" : "PG-13",
"genre" : [
"Action",
"Crime",
"Drama"
]
}
},
{
"_index" : "movies",
"_type" : "_doc",
"_id" : "4",
"_score" : 1.0,
"_source" : {
"title" : "The Godfather: Part II",
"synopsis" : "The early life and career of Vito Corleone in 1920s New York City is portrayed, while his son, Michael, expands and tightens his grip on the family crime syndicate.",
"actors" : [
"Al Pacino",
"Robert De Niro",
"Robert Duvall",
"Diane Keaton"
],
"director" : " Francis Ford Coppola ",
"rating" : "9.0",
"certificate" : "R",
"genre" : [
"Crime",
"Drama"
]
}
},
{
"_index" : "movies",
"_type" : "_doc",
"_id" : "5",
"_score" : 1.0,
"_source" : {
"title" : "12 Angry Men",
"synopsis" : "A jury holdout attempts to prevent a miscarriage of justice by forcing his colleagues to reconsider the evidence.",
"actors" : [
"Henry Fonda",
"Lee J. Cobb",
"Martin Balsam",
" John Fiedler"
],
"director" : " Sidney Lumet ",
"rating" : "9.0",
"certificate" : "Approved",
"genre" : [
"Crime",
"Drama"
]
}
},
{
"_index" : "movies",
"_type" : "_doc",
"_id" : "6",
"_score" : 1.0,
"_source" : {
"title" : "The Lord of the Rings: The Return of the King",
"synopsis" : "Gandalf and Aragorn lead the World of Men against Saurons's army to draw his gaze from Frodo and Sam as they approach Mount Doom with the One Ring.",
"actors" : [
"Elijah Wood",
"Viggo Mortensen",
"Ian McKellen",
"Orlando Bloom"
],
"director" : " Peter Jackson ",
"rating" : "8.9",
"certificate" : "PG-13",
"genre" : [
"Action",
"Adventure",
"Drama"
]
}
},
{
"_index" : "movies",
"_type" : "_doc",
"_id" : "7",
"_score" : 1.0,
"_source" : {
"title" : "Pulp Fiction",
"synopsis" : "The lives of two mob hitmen, a boxer, a gangster and his wife, and a pair of diner bandits intertwine in four tales of violence and redemption.",
"actors" : [
"John Travolta",
"Uma Thurman",
"Samuel L. Jackson",
"Bruce Willis"
],
"director" : " Quentin Tarantino ",
"rating" : "8.9",
"certificate" : "R",
"genre" : [
"Crime",
"Drama"
]
}
},
{
"_index" : "movies",
"_type" : "_doc",
"_id" : "8",
"_score" : 1.0,
"_source" : {
"title" : "Schindler's List",
"synopsis" : "In German-occupied Poland during World War II, industrialist Oskar Schindler gradually becomes concerned for his Jewish workforce after witnessing their persecution by the Nazis.",
"actors" : [
"Liam Neeson",
"Ralph Fiennes",
"Ben Kingsley",
"Caroline Goodall"
],
"director" : " Steven Spielberg ",
"rating" : "8.9",
"certificate" : "R",
"genre" : [
"Biography",
"Drama",
"History"
]
}
},
{
"_index" : "movies",
"_type" : "_doc",
"_id" : "9",
"_score" : 1.0,
"_source" : {
"title" : "Inception",
"synopsis" : "A thief who steals corporate secrets through the use of dream-sharing technology is given the inverse task of planting an idea into the mind of a C.E.O.",
"actors" : [
"Leonardo DiCaprio",
"Joseph Gordon-Levitt",
"Elliot Page",
"Ken Watanabe"
],
"director" : " Christopher Nolan ",
"rating" : "8.8",
"certificate" : "PG-13",
"genre" : [
"Action",
"Adventure",
"Sci-Fi"
]
}
},
{
"_index" : "movies",
"_type" : "_doc",
"_id" : "10",
"_score" : 1.0,
"_source" : {
"title" : "Fight Club",
"synopsis" : "An insomniac office worker and a devil-may-care soap maker form an underground fight club that evolves into much more.",
"actors" : [
"Brad Pitt",
"Edward Norton",
"Meat Loaf",
"Zach Grenier"
],
"director" : " David Fincher ",
"rating" : "8.8",
"certificate" : "R",
"genre" : "Drama"
}
}
]
}
}
也可以直接查询所有索引情况
#查询索引情况
GET /_cat/indices?v
返回信息,movies的docs.count 25
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
green open movies ART5M7N8SC6hOBu0E3w87g 1 1 25 0 72.8kb 36.4kb
green open .apm-custom-link Xmj6MPxBT_ipIOZyTbwCQw 1 1 0 0 416b 208b
green open .kibana_task_manager_1 RmlBFYfNRSSXXJzlmMf8aA 1 1 5 98158 15.8mb 7.9mb
green open .apm-agent-configuration QFeI8NB1R8OeOnSy51Z92w 1 1 0 0 416b 208b
green open .kibana-event-log-7.10.1-000001 p-r29FQyT6KWlM4C_hvIMw 1 1 2 0 22kb 11kb
green open qqbq lVGlJpM0RXOrA8WfhMauTA 1 1 0 0 6.5kb 3.2kb
green open ffbf 7zMVV6IrQt6KrZBdIi26bw 2 2 0 0 37.2kb 16.8kb
green open .kibana_1 9JoNLVfYTsaxpsYufqKI7g 1 1 65 4 8.5mb 4.2mb
评论区