1.검색
엘라스틱서치의 검색 기능은 질의(query) 명령어를 이용해 수행된다.
*질의를 수행하는 방법은 2가지가 있다.
1) REST API
2) http 데이터를 이용한 request body 방식
검색 실습을 하기 위해 데이터를 입력하겠다. 입력할 데이터 예제 파일은 깃허브(github.com/wikibook/elasticsearch)에서 내려받았다.
접속하여 레파지토리에서 예제 파일을 다운로드받는다.
내려받은 예제파일의 05. 검색 디렉토리에 있는 5_1_books.json, 5_2_magazines.json 파일을 실습에 이용하겠다.
먼저 엘라스틱서치의 bulk API를 이용해서 5_1_books.json, 5_2_magazines.json 파일의 내용을 엘라스틱서치에 입력한다.
curl -XPOST 'http://localhost:9200/_bulk' -H 'Content-Type:application/json' --data-binary @5_1_books.json
curl -XPOST 'http://localhost:9200/_bulk' -H 'Content-Type:application/json' --data-binary @5_2_magazines.json
1.1 검색(_search) API
엘라스틱서치에서 검색은 인덱스 또는 타입 단위로 수행된다.
실습1) books 인덱스의 book 타입에서 halmet이라는 검색어로 검색을 수행한다.
- 검색은 _search API를 사용하며, 질의는 q 매개변수의 값으로 입력한다.
curl 'http://localhost:9200/books/book/_search?q=hamlet&pretty'
{
"took" : 3,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 1,
"relation" : "eq"
},
"max_score" : 4.278328,
"hits" : [
{
"_index" : "books",
"_type" : "book",
"_id" : "TGvKC3cBf7K4q_TS667E",
"_score" : 4.278328,
"_source" : {
"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."
}
}
]
}
}
실습2) 여러 인덱스 동시에 검색하기.
books 인덱스와 magazines 인게스에서 검색어 time으로 동시에 검색을 수행해보자.
* 멀티테넌시(multi tenancy) : 여러 인덱스를 동시에 검색하는 기능
- 사용 방법 : 검색할 인덱스를 쉽표(,)로 구분해서 입력하면 됨.
curl 'http://localhost:9200/books,magazines/_search?q=time&pretty'
{
"took" : 2,
"timed_out" : false,
"_shards" : {
"total" : 2,
"successful" : 2,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 6, // 총 6건의 데이터가 검색
"relation" : "eq"
},
"max_score" : 2.5739596,
"hits" : [
{
"_index" : "books",
"_type" : "book",
"_id" : "UmvKC3cBf7K4q_TS667E",
"_score" : 2.5739596,
"_source" : {
"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."
}
},
{
"_index" : "books",
"_type" : "book",
"_id" : "VmvKC3cBf7K4q_TS667E",
"_score" : 1.9426696,
"_source" : {
"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."
}
},
{
"_index" : "books",
"_type" : "book",
"_id" : "VGvKC3cBf7K4q_TS667E",
"_score" : 1.5109229,
"_source" : {
"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."
}
},
{
"_index" : "books",
"_type" : "book",
"_id" : "U2vKC3cBf7K4q_TS667E",
"_score" : 1.2768264,
"_source" : {
"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)."
}
},
{
"_index" : "magazines",
"_type" : "magazine",
"_id" : "WGvLC3cBf7K4q_TScK64",
"_score" : 1.2039728,
"_source" : {
"title" : "Time",
"company" : "Time Inc.",
"category" : "News magazine",
"issue" : "2014-03-01T00:00:00"
}
},
{
"_index" : "magazines",
"_type" : "magazine",
"_id" : "WWvLC3cBf7K4q_TScK65",
"_score" : 0.6931471,
"_source" : {
"title" : "People",
"company" : "Time Inc.",
"category" : "Human interest",
"issue" : "2013-10-01T00:00:00"
}
}
]
}
}
※ _all을 사용하여 클러스터의 모든 인덱스에서 검색을 할 수 도 있다. 또는 인덱스 자체를 생략해도 된다.
하지만 전체 클러스터 검색은 성능을 저하시키고 의도하지 않은 데이터가 검색되는 등 검색결과의 오염이 발생할 수 있으므로 될 수 있으 면 사용하지 않는 것을 권장한다.
1.2. URI 검색
엘라스틱서치의 두 가지 주요 검색 방법중 URI 검색을 먼저 살펴보자.
위 _search API의 실습은 모두 URI 검색 방법으로 진행했다.
1.2.1 q(query)
*q : 질의 명령을 입력하는 가장 기본적인 검색 매개변수
실습3) 특정 필드만 검색하기. title 필드에서 time을 검색해보자.
* 특정 필드만 검색하는 방법 : q={필드}:{검색어}
curl 'http://localhost:9200/books,magazines/_search?q=title:time&pretty'
{
"took" : 2,
"timed_out" : false,
"_shards" : {
"total" : 2,
"successful" : 2,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 2,
"relation" : "eq"
},
"max_score" : 2.5739596,
"hits" : [
{
"_index" : "books",
"_type" : "book",
"_id" : "UmvKC3cBf7K4q_TS667E",
"_score" : 2.5739596,
"_source" : {
"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."
}
},
{
"_index" : "magazines",
"_type" : "magazine",
"_id" : "WGvLC3cBf7K4q_TScK64",
"_score" : 1.2039728,
"_source" : {
"title" : "Time",
"company" : "Time Inc.",
"category" : "News magazine",
"issue" : "2014-03-01T00:00:00"
}
}
]
}
}
실습4) title 필드에 time과 machine이 동시에 들어간 값을 찾자.
- q 매개변수에 AND 또는 OR 값을 공백과 함께 넣어서 지정할 수 있다.
- 공백값은 인코딩 형식으로 입력해야 하므로 %20을 입력해야 한다.
curl 'http://localhost:9200/books,magazines/_search?q=title:time%20AND%20machine&pretty'
{
"took" : 9,
"timed_out" : false,
"_shards" : {
"total" : 2,
"successful" : 2,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 1,
"relation" : "eq"
},
"max_score" : 6.232274,
"hits" : [
{
"_index" : "books",
"_type" : "book",
"_id" : "UmvKC3cBf7K4q_TS667E",
"_score" : 6.232274,
"_source" : {
"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."
}
}
]
}
}
1.2.2 df(default field)
- q 질의에 필드명을 넣는 대신 df 매개변수를 사용해서 검색할 필드를 지정할 수 있다.
- 실습3의 q=title:time 와 q=time&df=title 이 동일한 결과를 출력한다.
curl 'http://localhost:9200/books,magazines/_search?q=time&df=title&pretty'
{
"took" : 63,
"timed_out" : false,
"_shards" : {
"total" : 2,
"successful" : 2,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 2,
"relation" : "eq"
},
"max_score" : 2.5739596,
"hits" : [
{
"_index" : "books",
"_type" : "book",
"_id" : "UmvKC3cBf7K4q_TS667E",
"_score" : 2.5739596,
"_source" : {
"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."
}
},
{
"_index" : "magazines",
"_type" : "magazine",
"_id" : "WGvLC3cBf7K4q_TScK64",
"_score" : 1.2039728,
"_source" : {
"title" : "Time",
"company" : "Time Inc.",
"category" : "News magazine",
"issue" : "2014-03-01T00:00:00"
}
}
]
}
}
1.2.3 default_operator
- q 매개변수에 조건 명령어 AND 와 OR를 질의로 사용할 수 있는 것을 확인했다.
조건 명령어를 지정하지 않고 공백으로 질의어를 나누면 OR로 인식한다. 다음 두 명령어는 같다.
1) /_search?q=title:time OR machine
2) /_search?q=title:time machine
default_operator 매개변수를 이용해서 기본 조건 명령어를 OR에서 AND로 변경할 수 있다.
어디에 유용하게 쓰이는건지는 아직 잘 모르겠다.
curl 'http://localhost:9200/books,magazines/_search?q=title:time%20machine&default_operator=AND&pretty'
{
"took" : 7,
"timed_out" : false,
"_shards" : {
"total" : 2,
"successful" : 2,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 1,
"relation" : "eq"
},
"max_score" : 6.232274,
"hits" : [
{
"_index" : "books",
"_type" : "book",
"_id" : "UmvKC3cBf7K4q_TS667E",
"_score" : 6.232274,
"_source" : {
"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."
}
}
]
}
}
1.2.4 explain
- explain 매개변수를 추가하면 각 검색 처리에 대해 해당 검색 결과의 점수 계산에 사용된 상세 값이 출력 결과에 표시된다.
- 점수는 해당 검색어에 대한 정확도를 계산한 값이며 점수가 높을수록 검색 결과 상위에 나타나게 된다.
책에는 그냥 explain을 매개변수로 넣으면 된다고 하는데 상세값이 나오지 않는다.
explain=true 까지 넣어줘야 그제서야 나온다. 책 내용대로 했다가 안되는 부분이 묘하게 많음..
curl 'http://localhost:9200/_search?q=title:time&explain=true&pretty'
{
"took" : 3,
"timed_out" : false,
"_shards" : {
"total" : 2,
"successful" : 2,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 2,
"relation" : "eq"
},
"max_score" : 2.5739596,
"hits" : [
{
"_shard" : "[books][0]",
"_node" : "rWXs4zxCTx6G3uc2S-wo8Q",
"_index" : "books",
"_type" : "book",
"_id" : "UmvKC3cBf7K4q_TS667E",
"_score" : 2.5739596,
"_source" : {
"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."
},
"_explanation" : {
"value" : 2.5739596,
"description" : "weight(title:time in 10) [PerFieldSimilarity], result of:",
"details" : [
{
"value" : 2.5739596,
"description" : "score(freq=1.0), computed as boost * idf * tf from:",
"details" : [
{
"value" : 2.2,
"description" : "boost",
"details" : [ ]
},
{
"value" : 2.3671236,
"description" : "idf, computed as log(1 + (N - n + 0.5) / (n + 0.5)) from:",
"details" : [
{
"value" : 1,
"description" : "n, number of documents containing term",
"details" : [ ]
},
{
"value" : 15,
"description" : "N, total number of documents with field",
"details" : [ ]
}
]
},
{
"value" : 0.494263,
"description" : "tf, computed as freq / (freq + k1 * (1 - b + b * dl / avgdl)) from:",
"details" : [
{
"value" : 1.0,
"description" : "freq, occurrences of term within document",
"details" : [ ]
},
{
"value" : 1.2,
"description" : "k1, term saturation parameter",
"details" : [ ]
},
{
"value" : 0.75,
"description" : "b, length normalization parameter",
"details" : [ ]
},
{
"value" : 3.0,
"description" : "dl, length of field",
"details" : [ ]
},
{
"value" : 3.7333333,
"description" : "avgdl, average length of field",
"details" : [ ]
}
]
}
]
}
]
}
},
{
"_shard" : "[magazines][0]",
"_node" : "rWXs4zxCTx6G3uc2S-wo8Q",
"_index" : "magazines",
"_type" : "magazine",
"_id" : "WGvLC3cBf7K4q_TScK64",
"_score" : 1.2039728,
"_source" : {
"title" : "Time",
"company" : "Time Inc.",
"category" : "News magazine",
"issue" : "2014-03-01T00:00:00"
},
"_explanation" : {
"value" : 1.2039728,
"description" : "weight(title:time in 1) [PerFieldSimilarity], result of:",
"details" : [
{
"value" : 1.2039728,
"description" : "score(freq=1.0), computed as boost * idf * tf from:",
"details" : [
{
"value" : 2.2,
"description" : "boost",
"details" : [ ]
},
{
"value" : 1.2039728,
"description" : "idf, computed as log(1 + (N - n + 0.5) / (n + 0.5)) from:",
"details" : [
{
"value" : 1,
"description" : "n, number of documents containing term",
"details" : [ ]
},
{
"value" : 4,
"description" : "N, total number of documents with field",
"details" : [ ]
}
]
},
{
"value" : 0.45454544,
"description" : "tf, computed as freq / (freq + k1 * (1 - b + b * dl / avgdl)) from:",
"details" : [
{
"value" : 1.0,
"description" : "freq, occurrences of term within document",
"details" : [ ]
},
{
"value" : 1.2,
"description" : "k1, term saturation parameter",
"details" : [ ]
},
{
"value" : 0.75,
"description" : "b, length normalization parameter",
"details" : [ ]
},
{
"value" : 1.0,
"description" : "dl, length of field",
"details" : [ ]
},
{
"value" : 1.0,
"description" : "avgdl, average length of field",
"details" : [ ]
}
]
}
]
}
]
}
}
]
}
}
1.2.5 _source
- _source 매개변수 값을 false로 설정하면 검색 결과에서 도큐먼트 내용은 표시하지 않고 메타 정보만 출력된다.
curl 'http://localhost:9200/_search?q=title:time&_source=false&pretty'
{
"took" : 2,
"timed_out" : false,
"_shards" : {
"total" : 2,
"successful" : 2,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 2,
"relation" : "eq"
},
"max_score" : 2.5739596,
"hits" : [
{
"_index" : "books",
"_type" : "book",
"_id" : "UmvKC3cBf7K4q_TS667E",
"_score" : 2.5739596
},
{
"_index" : "magazines",
"_type" : "magazine",
"_id" : "WGvLC3cBf7K4q_TScK64",
"_score" : 1.2039728
}
]
}
}
1.2.6 fields
- 출력 결과에 표시하고 싶은 필드만 별도 지정할 때 사용한다.
- RDB 테이블에서 select (column1),(column2).... 와 같은 기능인것 같다.
그런데 오류가 뜨면서 되지 않는다.
curl 'http://localhost:9200/_search?q=title:time&fields=title,author,category&pretty'
{
"error" : {
"root_cause" : [
{
"type" : "illegal_argument_exception",
"reason" : "request [/_search] contains unrecognized parameter: [fields]"
}
],
"type" : "illegal_argument_exception",
"reason" : "request [/_search] contains unrecognized parameter: [fields]"
},
"status" : 400
}
fields --> _source로 변경되었다.
curl 'http://localhost:9200/_search?q=title:time&_source=title,author,category&pretty'
{
"took" : 3,
"timed_out" : false,
"_shards" : {
"total" : 2,
"successful" : 2,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 2,
"relation" : "eq"
},
"max_score" : 2.5739596,
"hits" : [
{
"_index" : "books",
"_type" : "book",
"_id" : "UmvKC3cBf7K4q_TS667E",
"_score" : 2.5739596,
"_source" : {
"author" : "H. G. Wells",
"title" : "The Time Machine",
"category" : "Science fiction novel"
}
},
{
"_index" : "magazines",
"_type" : "magazine",
"_id" : "WGvLC3cBf7K4q_TScK64",
"_score" : 1.2039728,
"_source" : {
"title" : "Time",
"category" : "News magazine"
}
}
]
}
}
1.2.7 sort
- 검색 결과의 출력 순서를 정하는데 사용된다.
기본적으로 검색결과는 점수(_source)값을 기준으로 정렬된다.
- RDB의 order by 와 같은 역할 인듯
- 사용 방법:
- 오름 차순(default) : sort=필드명:asc (:asc는 생략 가능)
- 내림 차순 : sort=필드명:desc
실습5) books 인덱스에서 author필드가 jules인 도큐먼트를 pages 필드를 기준으로 오름차순 정렬과 내림차순 정렬로 검색해보자.
- 오름차순
pages가 189, 212, 304 로 쪽수가 적은 book부터 검색된다.
curl 'http://localhost:9200/books/_search?q=author:jules&sort=pages&pretty'
{
"took" : 25,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 3,
"relation" : "eq"
},
"max_score" : null,
"hits" : [
{
"_index" : "books",
"_type" : "book",
"_id" : "VmvKC3cBf7K4q_TS667E",
"_score" : null,
"_source" : {
"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."
},
"sort" : [
189
]
},
{
"_index" : "books",
"_type" : "book",
"_id" : "VWvKC3cBf7K4q_TS667E",
"_score" : null,
"_source" : {
"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."
},
"sort" : [
212
]
},
{
"_index" : "books",
"_type" : "book",
"_id" : "VGvKC3cBf7K4q_TS667E",
"_score" : null,
"_source" : {
"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."
},
"sort" : [
304
]
}
]
}
}
- 내림차순
반대로 304, 212,189 로 페이지수가 많은 book부터 검색된다.
curl 'http://localhost:9200/books/_search?q=author:jules&sort=pages:desc&pretty'
{
"took" : 1,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 3,
"relation" : "eq"
},
"max_score" : null,
"hits" : [
{
"_index" : "books",
"_type" : "book",
"_id" : "VGvKC3cBf7K4q_TS667E",
"_score" : null,
"_source" : {
"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."
},
"sort" : [
304
]
},
{
"_index" : "books",
"_type" : "book",
"_id" : "VWvKC3cBf7K4q_TS667E",
"_score" : null,
"_source" : {
"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."
},
"sort" : [
212
]
},
{
"_index" : "books",
"_type" : "book",
"_id" : "VmvKC3cBf7K4q_TS667E",
"_score" : null,
"_source" : {
"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."
},
"sort" : [
189
]
}
]
}
}