예제 데이터 파일 및 코드들입니다.
책에 소개된 화면 링크와 예제 코드들은 각 장 폴더의 README.md 파일에 기록되어 있습니다.
『시작하세요! 엘라스틱서치』 예제 코드
예제 데이터 파일 및 코드들입니다.
책에 소개된 화면 링크와 예제 코드들은 각 장 폴더의 README.md 파일에 기록되어 있습니다.
$ curl -XGET localhost:9200/books/book/1?pretty
{
"_index" : "books",
"_type" : "book",
"_id" : "1",
"_version" : 7,
"found" : true,
"_source":{"title":"Elasticsearch Guide","author":["Lee","Kim"],"date":"2014-05-01","pages":100,"category":"ICT"}
}
$ curl -XPOST localhost:9200/books/book/1/_update -d '
{
"script" : "ctx._source.pages <= page_cnt ? ctx.op = "delete" : ctx.op = "none"",
"params" : { "page_cnt" : 100 }
}'
{"error":"ElasticsearchIllegalArgumentException[failed to execute script]; nested: GroovyScriptCompilationException[MultipleCompilationErrorsException[startup failed:\ndee3e9595063324c5eefca69415014b656351e98: 1: \nclass org.codehaus.groovy.ast.expr.TernaryExpression, with its value '((ctx._source.pages <= page_cnt)) ? (ctx.op = delete) : ctx.op', is a bad expression as the left hand side of an assignment operator at line: 1 column: 60. File: dee3e9595063324c5eefca69415014b656351e98 @ line 1, column 60.\n ? ctx.op = "delete" : ctx.op = "none"\n ^\n\n1 error\n]]; ","status":400}
참고로 script관련해서 에러가 발생을 해서 elasticsearch.yml에 다음을 추가를 했습니다.
script.inline: on
현재 버전은 1.7.4 입니다.
김찬일님의 아리랑 형태소 분석기가 더이상 개발이 안 되는 것 같은데,
ES 2.0이상을 지원하는 한글 형태소 분석기는 어디 있을까요?
5장의 검색에서 bulk api를 사용해서 ES에 업로드하는 부분이 있는데
ES 5.3에서는 create 할때 id 값이 없으면 올라가지 않습니다.
elastic/elasticsearch#21535
에서 확인했구요
제가 id 값을 넣어서 테스트 성공한 books.json 입니다.
{ "create" : { "_index": "books", "_type": "book", "_id" : 1 } }
{ "title": "The Tempest", "author": "William Shakespeare", "category":"Comedies", "written": "1610-03-01T11:34:00", "pages" : 62, "sell" : 275600000, "plot": "Magician Prospero, rightful Duke of Milan, and his daughter, Miranda, have been stranded for twelve years on an island after Prospero's jealous brother Antonio (aided by Alonso, the King of Naples) deposed him and set him adrift with the then-3-year-old Miranda. Gonzalo, the King's counsellor, had secretly supplied their boat with plenty of food, water, clothes and the most-prized books from Prospero's library. Possessing magic powers due to his great learning, Prospero is reluctantly served by a spirit, Ariel, whom Prospero had rescued from a tree in which he had been trapped by the witch Sycorax. Prospero maintains Ariel's loyalty by repeatedly promising to release the "airy spirit" from servitude. Sycorax had been banished to the island, and had died before Prospero's arrival. Her son, Caliban, a deformed monster and the only non-spiritual inhabitant before the arrival of Prospero, was initially adopted and raised by him. He taught Prospero how to survive on the island, while Prospero and Miranda taught Caliban religion and their own language. Following Caliban's attempted rape of Miranda, he had been compelled by Prospero to serve as the magician's slave. In slavery, Caliban has come to view Prospero as a usurper and has grown to resent him and his daughter. Prospero and Miranda in turn view Caliban with contempt and disgust."}
{ "create" : { "_index": "books", "_type": "book", "_id" : 2 } }
{ "title": "The Merchant of Venice", "author": "William Shakespeare", "category":"Comedies", "written": "1596-02-01T04:42:00", "pages" : 97, "sell" : 124100000, "plot": "Bassanio, a young Venetian of noble rank, wishes to woo the beautiful and wealthy heiress Portia of Belmont. Having squandered his estate, he needs 3,000 ducats to subsidise his expenditures as a suitor. Bassanio approaches his friend Antonio, a wealthy merchant of Venice who has previously and repeatedly bailed him out. Antonio agrees, but since he is cash-poor ? his ships and merchandise are busy at sea ? he promises to cover a bond if Bassanio can find a lender, so Bassanio turns to the Jewish moneylender Shylock and names Antonio as the loan's guarantor." }
{ "create" : { "_index": "books", "_type": "book" , "_id" : 3} }
{ "title": "Romeo and Juliet", "author": "William Shakespeare", "category":"Tragedies", "written": "1562-12-01T20:40:00", "pages" : 125, "sell" : 182700000, "plot": "Meanwhile, Benvolio talks with his cousin Romeo, Montague's son, about Romeo's recent depression. Benvolio discovers that it stems from unrequited infatuation for a girl named Rosaline, one of Capulet's nieces. Persuaded by Benvolio and Mercutio, Romeo attends the ball at the Capulet house in hopes of meeting Rosaline. However, Romeo instead meets and falls in love with Juliet. Juliet's cousin, Tybalt, is enraged at Romeo for sneaking into the ball, but is only stopped from killing Romeo by Juliet's father, who doesn't wish to shed blood in his house. After the ball, in what is now called the "balcony scene", Romeo sneaks into the Capulet orchard and overhears Juliet at her window vowing her love to him in spite of her family's hatred of the Montagues. Romeo makes himself known to her and they agree to be married. With the help of Friar Laurence, who hopes to reconcile the two families through their children's union, they are secretly married the next day." }
{ "create" : { "_index": "books", "_type": "book" , "_id" : 4 } }
{ "title": "King Lear", "author": "William Shakespeare", "category":"Tragedies", "written": "1603-05-01T04:36:00", "pages" : 88, "sell" : 91300000, "plot" : "In the first scene the Earl of Gloucester and the Earl of Kent meet and observe that King Lear has awarded equal shares of his realm to the Duke of Cornwall and the Duke of Albany (and even before this the formal division of the next scene has taken place). Then the Earl of Gloucester introduces his illegitimate son Edmund to the Earl of Kent. In the next scene, King Lear, who is elderly and wants to retire from power, decides to divide his realm among his three daughters, and declares he'll offer the largest share to the one who loves him best. The eldest, Goneril, speaks first, declaring her love for her father in fulsome terms. Moved by her flattery Lear proceeds to grant to Goneril her share as soon as she's finished her declaration, before Regan and Cordelia have a chance to speak. He then awards to Regan her share as soon as she has spoken. When it is finally the turn of his youngest daughter, Cordelia, at first she refuses to say anything ("Nothing, my Lord") and then declares there is nothing to compare her love to, nor words to properly express it; she speaks honestly but bluntly, which infuriates him. In his anger he disinherits Cordelia and divides her share between Regan and Goneril. Kent objects to this unfair treatment. Enraged by Kent's protests, Lear banishes him from the country. Lear summons the Duke of Burgundy and the King of France, who have both proposed marriage to Cordelia. Learning that Cordelia has been disinherited, the Duke of Burgundy withdraws his suit, but the King of France is impressed by her honesty and marries her anyway." }
{ "create" : { "_index": "books", "_type": "book" , "_id" : 5 } }
{ "title": "Hamlet", "author": "William Shakespeare", "category":"Tragedies", "written": "1599-06-01T12:34:00", "pages" : 172, "sell" : 146100000, "plot": "The protagonist of Hamlet is Prince Hamlet of Denmark, son of the recently deceased King Hamlet, and nephew of King Claudius, his father's brother and successor. Claudius hastily married King Hamlet's widow, Gertrude, Hamlet's mother. Denmark has a long-standing feud with neighbouring Norway, and an invasion led by the Norwegian prince, Fortinbras, is expected." }
{ "create" : { "_index": "books", "_type": "book" , "_id" : 6 } }
{ "title": "Othello", "author": "William Shakespeare", "category":"Tragedies", "written": "1603-07-01T13:34:00", "pages" : 100, "sell" : 141200000, "plot": "Before Brabantio reaches Othello, news arrives in Venice that the Turks are going to attack Cyprus; therefore Othello is summoned to advise the senators. Brabantio arrives and accuses Othello of seducing Desdemona by witchcraft, but Othello defends himself successfully before an assembly that includes the Duke of Venice, Brabantio's kinsmen Lodovico and Gratiano, and various senators. He explains that Desdemona became enamored of him for the sad and compelling stories he told of his life before Venice, not because of any witchcraft. The senate is satisfied, but Brabantio leaves saying that Desdemona will betray Othello. By order of the Duke, Othello leaves Venice to command the Venetian armies against invading Turks on the island of Cyprus, accompanied by his new wife, his new lieutenant Cassio, his ensign Iago, and Iago's wife, Emilia as Desdemona's attendant." }
{ "create" : { "_index": "books", "_type": "book" , "_id" : 7 } }
{ "title": "The Adventures of Tom Sawyer", "author": "Mark Twain", "category":"Folk", "written": "1876-03-01T01:34:00", "pages" : 220, "sell" : 83200000, "plot": "Tom Sawyer lives with his Aunt Polly and his half-brother, Sid. Tom dirties his clothes in a fight and is made to whitewash the fence the next day, as a punishment. He cleverly persuades his friends to trade him small treasures for the privilege of doing his work. He trades the treasures for Sunday School tickets which one normally receives for memorizing scriptures, redeeming them for a bible, much to the surprise and bewilderment of the superintendent who thought "it was simply preposterous that this boy had warehoused two thousand sheaves of Scriptural wisdom on his premises?a dozen would strain his capacity, without a doubt."" }
{ "create" : { "_index": "books", "_type": "book" , "_id" : 8 } }
{ "title": "The Prince and the Pauper", "author": "Mark Twain", "category":"Children's literature", "written": "1881-08-01T10:34:00", "pages" : 79, "sell" : 112100000, "plot": "Tom Canty (youngest son of a family living with the dregs of society in Offal Court) has always aspired to a better life, encouraged by the local priest (who has taught him to read and write). Loitering around the palace gates one day, he sees a prince (the Prince of Wales ? Edward VI). Tom is nearly caught and beaten by the Royal Guards; however, Edward stops them and invites Tom into his palace chamber. There the two boys get to know one another, fascinated by each other's life and their uncanny resemblance. They decide to switch clothes "temporarily". Edward leaves in a hurry before the boys are caught at their game, snatching up an article of national importance (which the reader later learns is the Great Seal of England). Soon Prince Edward is trying to escape the brutality of Tom's abusive drunken father. Tom, posing as the prince, tries to cope with court customs and manners. His fellow nobles and palace staff think "the prince" has an illness which has caused memory loss and fear he will go mad. They repeatedly ask him about the missing "Great Seal", but he knows nothing about it; however, when Tom is asked to sit in on judgments, his common-sense observations reassure them his mind is sound." }
{ "create" : { "_index": "books", "_type": "book" , "_id" : 8 } }
{ "title": "The Count of Monte Cristo", "author": "Alexandre Dumas", "category":"Historical novel", "written": "1844-09-01T12:24:00", "pages" : 435, "sell" : 49200000, "plot": "In 1815 Edmond Dantes, a young and successful merchant sailor who has just recently been granted the succession of his erstwhile captain Leclere, returns to Marseille to marry his Catalan fiancee Mercedes. Leclere, a supporter of the exiled Napoleon I, found himself dying at sea and charged Dantes to deliver two objects: a package to Marshall Bertrand (exiled with Napoleon Bonaparte on Elba), and a letter from Elba to an unknown man in Paris. On the eve of his wedding to Mercedes, Fernand (Mercedes' cousin and a rival for her affections) is given subtle advice by Dantes' colleague Danglars (who is jealous of his rapid rise to captain), to send an anonymous note accusing Dantes of being a Bonapartist traitor. Caderousse (Dantes' cowardly and selfish neighbor) is drunk while the two conspirators set the trap for Dantes, and while he objects to the idea of hurting Dantes, he stays quiet the next day as Dantes is arrested then sentenced even though his testimony could have stopped the entire scandal from happening. Villefort, the deputy crown prosecutor in Marseille, while initially sympathetic to Dantes, destroys the letter from Elba when he discovers that it is addressed to his own father, a Bonapartist. In order to silence Dantes, he condemns him without trial to life imprisonment." }
{ "create" : { "_index": "books", "_type": "book" , "_id" : 9 } }
{ "title": "The Three Musketeers", "author": "Alexandre Dumas", "category":"Historical novel", "written": "1844-10-01T12:00:00", "pages" : 340, "sell" : 61400000, "plot": "In 1625 France, d'Artagnan?a poor young nobleman?leaves his family in Gascony and travels to Paris with the intention of joining the Musketeers of the Guard. However, en route, at an inn in Meung-sur-Loire, an older man derides d'Artagnan's horse and, feeling insulted, d'Artagnan demands to fight a duel with him. The older man's companions beat d'Artagnan unconscious with a pot and a metal tong that breaks his sword. His letter of introduction to Monsieur de Treville, the commander of the Musketeers, is stolen. D'Artagnan resolves to avenge himself upon the man, who is later revealed to be the Comte de Rochefort, an agent of Cardinal Richelieu, who is in Meung to pass orders from the Cardinal to Milady de Winter, another of his agents." }
{ "create" : { "_index": "books", "_type": "book" , "_id" : 10 } }
{ "title": "The Time Machine", "author": "H. G. Wells", "category":"Science fiction novel", "written": "1895-11-01T05:01:00", "pages" : 227, "sell" : 22100000, "plot": "The book's protagonist is an English scientist and gentleman inventor living in Richmond, Surrey in Victorian England, and identified by a narrator simply as the Time Traveller. The narrator recounts the Traveller's lecture to his weekly dinner guests that time is simply a fourth dimension, and his demonstration of a tabletop model machine for travelling through it. He reveals that he has built a machine capable of carrying a person, and returns at dinner the following week to recount a remarkable tale, becoming the new narrator." }
{ "create" : { "_index": "books", "_type": "book" , "_id" : 11 } }
{ "title": "The Invisible Man", "author": "H. G. Wells", "category":["Horror", "Science fiction novel"], "written": "1897-05-01T07:32:00", "pages" : 210, "sell" : 67800000, "plot": "A mysterious stranger, Griffin, arrives at the local inn of the English village of Iping, West Sussex, during a snowstorm. The stranger wears a long-sleeved, thick coat and gloves, his face hidden entirely by bandages except for a fake pink nose, and a wide-brimmed hat. He is excessively reclusive, irascible, and unfriendly. He demands to be left alone and spends most of his time in his rooms working with a set of chemicals and laboratory apparatus, only venturing out at night. While staying at the inn, hundreds of strange glass bottles arrive that Griffin calls his luggage. Many local townspeople believe this to be very strange. He becomes the talk of the village (one of the novel's most charming aspects is its portrayal of small-town life in southern England, which the author knew from first-hand experience)." }
{ "create" : { "_index": "books", "_type": "book" , "_id" : 12 } }
{ "title": "Twenty Thousand Leagues Under the Sea", "author": "Jules Verne", "category":["Science fiction", "adventure novel"], "written": "1870-06-01T10:34:00", "pages" : 304, "sell" : 78100000, "plot": "In the year 1866, ships of several nations spot a mysterious sea monster, which some suggest to be a giant narwhal. The United States government assembles an expedition in New York City to find and destroy the monster. Professor Pierre Aronnax, a French marine biologist and narrator of the story, who happens to be in New York at the time, receives a last-minute invitation to join the expedition which he accepts. Canadian master harpoonist Ned Land and Aronnax's faithful servant Conseil are also brought aboard." }
{ "create" : { "_index": "books", "_type": "book" , "_id" : 13 } }
{ "title": "Journey to the Center of the Earth", "author": "Jules Verne", "category":["Science fiction", "adventure novel"], "written": "1864-07-01T11:30:00", "pages" : 212, "sell" : 42100000, "plot": "Professor Lidenbrock decides to lock everyone in the house and force himself and the others (Axel, and the maid, Martha) to go without food until he cracks the code. Axel discovers the answer when fanning himself with the deciphered text: Lidenbrock's decipherment was correct, and only needs to be read backwards to reveal sentences written in rough Latin." }
{ "create" : { "_index": "books", "_type": "book" , "_id" : 14 } }
{ "title": "Around the World in Eighty Days", "author": "Jules Verne", "category":"adventure novel", "written": "1873-07-01T10:30:00", "pages" : 189, "sell" : 27200000, "plot": "Fogg and Passepartout reach Suez in time. While disembarking in Egypt, they are watched by a Scotland Yard detective named Fix, who has been dispatched from London in search of a bank robber. Because Fogg matches the description of the robber, Fix mistakes Fogg for the criminal. Since he cannot secure a warrant in time, Fix boards the steamer conveying the travellers to Bombay. Fix becomes acquainted with Passepartout without revealing his purpose. Fogg promises the steamer engineer a large reward if he gets them to Bombay early. They dock two days ahead of schedule." }
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.