Your SlideShare is downloading. ×
0
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Terms of endearment - the ElasticSearch Query DSL explained

58,377

Published on

An introduction to mapping, analyzers, and how to query ElasticSearch using the Perl API

An introduction to mapping, analyzers, and how to query ElasticSearch using the Perl API

Published in: Technology
4 Comments
111 Likes
Statistics
Notes
  • awesome ppt.. any clue where can i hear your ppt talk? Any further lilnk will be great....thanks :D
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Awesome slide. I wish I had found this before I jumped into ElasticSearch. This should be included in the official documentation for ES since the current Guide/API Docs is seriously lacking these information, especially for newbies like myself.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • When viewed on Chrome on 1/16/13, some of the slides do not display correctly. http://i.imgur.com/HXFCE.png (HXFCE.png file at imgur). However, if I download and view in Power Point, it's fine.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Great presentation!
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total Views
58,377
On Slideshare
0
From Embeds
0
Number of Embeds
14
Actions
Shares
0
Downloads
993
Comments
4
Likes
111
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. “ Terms of Endearment” The ElasticSearch query language explained Clinton Gormley, YAPC::EU 2011 DRTECH @clintongormley
  • 2. search for : “ DELETE QUERY ” We can
  • 3. search for : “ DELETE QUERY ” and find : “ deleteByQuery ” We can
  • 4. but you can only find what is stored in the database
  • 5. Normalise values “ deleteByQuery” 'delete' 'by' 'query' 'deletebyquery'
  • 6. Normalise values and search terms “ deleteByQuery” “ DELETE QUERY” ' delete ' 'by' ' query ' 'deletebyquery'
  • 7. Normalise values and search terms “ deleteByQuery” “ DELETE QUERY” ' delete ' 'by' ' query ' 'deletebyquery'
  • 8. Analyse values and search terms “ deleteByQuery” “ DELETE QUERY” ' delete ' 'by' ' query ' 'deletebyquery'
  • 9. What is stored in ElasticSearch?
  • 10. { tweet => "Perl is GREAT!", posted => "2011-08-15", user => { name => "Clinton Gormley", email => "drtech@cpan.org", }, tags => [" perl" ,"opinion"], posts => 2, } Document:
  • 11. { tweet => "Perl is GREAT!", posted => "2011-08-15", user => { name => "Clinton Gormley", email => "drtech@cpan.org", }, tags => [" perl" ,"opinion"], posts => 2, } Fields:
  • 12. { tweet => "Perl is GREAT!", posted => "2011-08-15", user => { name => "Clinton Gormley", email => "drtech@cpan.org", }, tags => [" perl" ,"opinion"], posts => 2, } Values:
  • 13. { tweet => "Perl is GREAT!", posted => "2011-08-15", user => { name => "Clinton Gormley", email => "drtech@cpan.org" }, tags => [" perl" ,"opinion"], posts => 2, } Field types: # object # string # date # nested object # string # string # array of enums # integer
  • 14. { tweet => "Perl is GREAT!", posted => "2011-08-15", user => { name => "Clinton Gormley", email => "drtech@cpan.org", }, tags => [" perl" ,"opinion"], posts => 2, } Nested objects flattened:
  • 15. { tweet => "Perl is GREAT!", posted => "2011-08-15", user.name => "Clinton Gormley", user.email => "drtech@cpan.org", tags => [" perl" ,"opinion"], posts => 2, } Nested objects flattened
  • 16. { tweet => "Perl is GREAT!", posted => "2011-08-15", user.name => "Clinton Gormley", user.email => "drtech@cpan.org", tags => [" perl" ,"opinion"], posts => 2, } Values analyzed into terms
  • 17. { tweet => ['perl','great'], posted => [Date(2011-08-15)], user.name => ['clinton','gormley'], user.email => ['drtech','cpan.org'], tags => [' perl' ,'opinion'], posts => [2], } Values analyzed into terms
  • 18. database table row ⇒ many tables ⇒ many rows ⇒ one schema ⇒ many columns In MySQL
  • 19. index type document ⇒ many types ⇒ many documents ⇒ one mapping ⇒ many fields In ElasticSearch
  • 20. Create index with mappings $es-> create_index ( index => 'twitter', mappings => { tweet => { properties => { title => { type => 'string' }, created => { type => 'date' } } } } );
  • 21. Add a mapping $es-> put_mapping ( index => 'twitter', type => ' user ', mapping => { properties => { name => { type => 'string' }, created => { type => 'date' }, } } );
  • 22. Can add to existing mapping
  • 23. Can add to existing mapping Cannot change mapping for field
  • 24. Core field types { type => 'string', }
  • 25. Core field types { type => 'string', # byte|short|integer|long|double|float # date, ip addr, geolocation # boolean # binary (as base 64) }
  • 26. Core field types { type => 'string', index => ' analyzed ', # 'Foo Bar' ⇒ [ 'foo', 'bar' ] }
  • 27. Core field types { type => 'string', index => ' not_analyzed ', # 'Foo Bar' ⇒ [ 'Foo Bar' ] }
  • 28. Core field types { type => 'string', index => ' no ', # 'Foo Bar' ⇒ [ ] }
  • 29. Core field types { type => 'string', index => 'analyzed', analyzer => 'default', }
  • 30. Core field types { type => 'string', index => 'analyzed', index_ analyzer => 'default', search_ analyzer => 'default', }
  • 31. Core field types { type => 'string', index => 'analyzed', analyzer => 'default', boost => 2, }
  • 32. Core field types { type => 'string', index => 'analyzed', analyzer => 'default', boost => 2, include_in_all => 1 |0 }
  • 33. <ul><li>Standard
  • 34. Simple
  • 35. Whitespace
  • 36. Stop
  • 37. Keyword </li></ul>Built in analyzers <ul><li>Pattern
  • 38. Language
  • 39. Snowball
  • 40. Custom </li></ul>
  • 41. The Brown-Cow&apos;s Part_No. #A.BC123-456 joe@bloggs.com keyword: The Brown-Cow&apos;s Part_No. #A.BC123-456 joe@bloggs.com whitespace: The, Brown-Cow&apos;s, Part_No., #A.BC123-456, joe@bloggs.com simple: the, brown, cow, s, part, no, a, bc, joe, bloggs, com standard: brown, cow&apos;s, part_no, a.bc123, 456, joe, bloggs.com snowball (English): brown, cow, part_no, a.bc123, 456, joe, bloggs.com
  • 42. Token filters <ul><li>Standard
  • 43. ASCII Folding
  • 44. Length
  • 45. Lowercase
  • 46. NGram
  • 47. Edge NGram
  • 48. Porter Stem
  • 49. Shingle
  • 50. Stop
  • 51. Word Delimiter </li></ul><ul><li>Stemmer
  • 52. KStem
  • 53. Snowball
  • 54. Phonetic
  • 55. Synonym
  • 56. Compound Word
  • 57. Reverse
  • 58. Elision
  • 59. Truncate
  • 60. Unique </li></ul>
  • 61. Custom Analyzer $c-&gt;create_index( index =&gt; &apos;twitter&apos;, settings =&gt; { analysis =&gt; { analyzer =&gt; { ascii_html =&gt; { type =&gt; &apos;custom&apos;, tokenizer =&gt; &apos;standard&apos;, filter =&gt; [ qw( standard lowercase asciifolding stop ) ], char_filter =&gt; [&apos;html_strip&apos;] } } }} );
  • 62. Searching $result = $es-&gt;search( index =&gt; &apos;twitter&apos;, type =&gt; &apos;tweet&apos;, );
  • 63. Searching $result = $es-&gt;search( index =&gt; [&apos;twitter&apos;,&apos;facebook&apos;] , type =&gt; [&apos;tweet&apos;,&apos;post&apos;] , );
  • 64. Searching $result = $es-&gt;search( # all indices # all types );
  • 65. Searching $result = $es-&gt;search( index =&gt; &apos;twitter&apos;, type =&gt; &apos;tweet&apos;, query =&gt; { text =&gt; { _all =&gt; &apos;foo&apos; }}, );
  • 66. Searching $result = $es-&gt;search( index =&gt; &apos;twitter&apos;, type =&gt; &apos;tweet&apos;, query b =&gt; &apos;foo&apos; , # b == ElasticSearch::SearchBuilder );
  • 67. Searching $result = $es-&gt;search( index =&gt; &apos;twitter&apos;, type =&gt; &apos;tweet&apos;, query =&gt; { text =&gt; { _all =&gt; &apos;foo&apos; }}, sort =&gt; [{ &apos;_score&apos;: &apos;desc&apos; }] );
  • 68. Searching $result = $es-&gt;search( index =&gt; &apos;twitter&apos;, type =&gt; &apos;tweet&apos;, query =&gt; { text =&gt; { _all =&gt; &apos;foo&apos; }}, sort =&gt; [{ &apos;_score&apos;: &apos;desc&apos; }] from =&gt; 0, size =&gt; 10, );
  • 69. Query DSL
  • 70. Queries vs Filters
  • 71. Queries vs Filters <ul><li>full text &amp; terms </li></ul><ul><li>terms only </li></ul>
  • 72. Queries vs Filters <ul><li>full text &amp; terms
  • 73. relevance scoring </li></ul><ul><li>terms only
  • 74. no scoring </li></ul>
  • 75. Queries vs Filters <ul><li>full text &amp; terms
  • 76. relevance scoring
  • 77. slower </li></ul><ul><li>terms only
  • 78. no scoring
  • 79. faster </li></ul>
  • 80. Queries vs Filters <ul><li>full text &amp; terms
  • 81. relevance scoring
  • 82. slower
  • 83. no caching </li></ul><ul><li>terms only
  • 84. no scoring
  • 85. faster
  • 86. cacheable </li></ul>
  • 87. Queries vs Filters <ul><li>full text &amp; terms
  • 88. relevance scoring
  • 89. slower
  • 90. no caching </li></ul><ul><li>terms only
  • 91. no scoring
  • 92. faster
  • 93. cacheable </li></ul>Use filters for anything that doesn&apos;t affect the relevance score!
  • 94. Query only Query DSL: $es-&gt;search( query =&gt; { text =&gt; { title =&gt; &apos;perl&apos; } } ); SearchBuilder: $es-&gt;search( query b =&gt; { title =&gt; &apos;perl&apos; } );
  • 95. Filter only Query DSL: $es-&gt;search( query =&gt; { constant_score =&gt; { filter =&gt; { term =&gt; { tag =&gt; &apos;perl } } } }); SearchBuilder: $es-&gt;search( query b =&gt; { -filter =&gt; { tag =&gt; &apos;perl&apos; } });
  • 96. Query and filter Query DSL: $es-&gt;search( query =&gt; { filtered =&gt; { query =&gt; { text =&gt; { title =&gt; &apos;perl&apos; } }, filter =&gt;{ term =&gt; { tag =&gt; &apos;perl&apos; } } } }); SearchBuilder: $es-&gt;search( query b =&gt; { title =&gt; &apos;perl&apos;, -filter =&gt; { tag =&gt; &apos;perl&apos; } });
  • 97. Filters
  • 98. Filters : equality Query DSL: { term =&gt; { tags =&gt; &apos;perl&apos; }} { terms =&gt; { tags =&gt; [&apos;perl&apos;,&apos;ruby&apos;] }} SearchBuilder: { tags =&gt; &apos;perl&apos; } { tags =&gt; [&apos;perl&apos;,&apos;ruby&apos;] }
  • 99. Filters : range Query DSL: { range =&gt; { date =&gt; { gte =&gt; &apos;2010-11-01&apos;, lt =&gt; &apos;2010-12-01&apos; }} SearchBuilder: { date =&gt; { gte =&gt; &apos;2010-11-01&apos;, lt =&gt; &apos;2011-12-01&apos; }}
  • 100. Filters : range (many values) Query DSL: { numeric_range =&gt; { date =&gt; { gte =&gt; &apos;2010-11-01&apos;, lt =&gt; &apos;2010-12-01 }} SearchBuilder: { date =&gt; { &apos; &gt;= &apos; =&gt; &apos;2010-11-01&apos;, &apos; &lt; &apos; =&gt; &apos;2011-12-01&apos; }}
  • 101. Filters : and | or | not Query DSL: { and =&gt; [ {term=&gt;{X=&gt;1}}, {term=&gt;{Y=&gt;2}} ]} { or =&gt; [ {term=&gt;{X=&gt;1}}, {term=&gt;{Y=&gt;2}} ]} { not =&gt; { or =&gt; [ {term=&gt;{X=&gt;1}}, {term=&gt;{Y=&gt;2}} ] }} SearchBuilder: { X =&gt; 1, Y =&gt; 2 } [ X =&gt; 1, Y =&gt; 2 ] { -not =&gt; { X =&gt; 1, Y =&gt; 2 } } # and { -not =&gt; [ X =&gt; 1, Y =&gt; 2 ] } # or
  • 102. Filters : exists | missing Query DSL: { exists =&gt; { field =&gt; &apos;title&apos; }} { missing =&gt; { field =&gt; &apos;title&apos; }} SearchBuilder: { -exists =&gt; &apos;title&apos; } { -missing =&gt; &apos;title&apos; }
  • 103. Filter example SearchBuilder: { -filter =&gt; [ featured =&gt; 1, { created_at =&gt; { gt =&gt; &apos;2011-08-01&apos; }, status =&gt; { &apos;!=&apos; =&gt; &apos;pending&apos; }, }, ] }
  • 104. Filter example Query DSL: { constant_score =&gt; { filter =&gt; { or =&gt; [ { term =&gt; { featured =&gt; 1 }}, { and =&gt; [ { not =&gt; { term =&gt; { status =&gt; &apos;pending&apos; }}, { range =&gt; { created_at =&gt; { gt =&gt; &apos;2011-08-01&apos; }}}, ] } ] } } }
  • 105. Filters : others <ul><li>script
  • 106. nested
  • 107. has_child
  • 108. query
  • 109. match_all
  • 110. prefix
  • 111. limit </li></ul><ul><li>ids
  • 112. type
  • 113. geo_distance
  • 114. geo_distance_range
  • 115. geo_bbox
  • 116. geo_polygon </li></ul>
  • 117. Text / Analyzed: <ul><li>text
  • 118. query_string / field
  • 119. flt / flt_field
  • 120. mlt / mlt_field </li></ul>Term / Not analyzed: <ul><li>term / terms
  • 121. range
  • 122. prefix
  • 123. fuzzy
  • 124. wildcard
  • 125. ids
  • 126. span queries </li></ul>Combining: <ul><li>bool
  • 127. dis_max
  • 128. boosting </li></ul>Scripting: <ul><li>custom_score
  • 129. custom_filters_score </li></ul>Wrappers: <ul><li>match_all
  • 130. constant_score
  • 131. filtered </li></ul>“ Joins”: <ul><li>nested
  • 132. has_child
  • 133. top_children </li></ul>Queries
  • 134. Text / Analyzed: <ul><li>text
  • 135. query_string / field
  • 136. flt / flt_field
  • 137. mlt / mlt_field </li></ul>Term / Not analyzed: <ul><li>term / terms
  • 138. range
  • 139. prefix
  • 140. fuzzy
  • 141. wildcard
  • 142. ids
  • 143. span queries </li></ul>Combining: <ul><li>bool
  • 144. dis_max
  • 145. boosting </li></ul>Scripting: <ul><li>custom_score
  • 146. custom_filters_score </li></ul>Wrappers: <ul><li>match_all
  • 147. constant_score
  • 148. filtered </li></ul>“ Joins”: <ul><li>nested
  • 149. has_child
  • 150. top_children </li></ul>Queries
  • 151. Text/Analyzed Queries mapping aware
  • 152. Text/Analyzed Queries not_analyzed ⇒ term query
  • 153. Text/Analyzed Queries analyzed ⇒ text query using search_analyzer
  • 154. Text-Query Family Query DSL: { text =&gt; { title =&gt; &apos;great perl&apos; }} Search Builder: { title =&gt; &apos;great perl&apos; }
  • 155. Text-Query Family Query DSL: { text =&gt; { title =&gt; { query =&gt; &apos;great perl&apos; }}} Search Builder: { title =&gt; { &apos;=&apos; =&gt; { query =&gt; &apos;great perl&apos; }}}
  • 156. Text-Query Family Query DSL: { text =&gt; { title =&gt; { query =&gt; &apos;great perl&apos; , operator =&gt; &apos;and&apos; }}} Search Builder: { title =&gt; { &apos;=&apos; =&gt; { query =&gt; &apos;great perl&apos;, operator =&gt; &apos;and&apos; }}}
  • 157. Text-Query Family Query DSL: { text =&gt; { title =&gt; { query =&gt; &apos;great perl&apos; , fuzziness =&gt; 0.5 }}} Search Builder: { title =&gt; { &apos;=&apos; =&gt; { query =&gt; &apos;great perl&apos;, fuzziness =&gt; 0.5 }}}
  • 158. Text-Query Family Query DSL: { text =&gt; { title =&gt; { query =&gt; &apos;great perl&apos;, type =&gt; &apos;phrase&apos; }}} Search Builder: { title =&gt; { &apos;==&apos; =&gt; { query =&gt; &apos;great perl&apos;, }}}
  • 159. Text-Query Family Query DSL: { text =&gt; { title =&gt; { query =&gt; &apos; great perl &apos;, type =&gt; &apos;phrase&apos; }}} Search Builder: { title =&gt; { &apos;==&apos; =&gt; { query =&gt; &apos; great perl &apos;, }}}
  • 160. Text-Query Family Query DSL: { text =&gt; { title =&gt; { query =&gt; &apos; perl is great &apos;, type =&gt; &apos;phrase&apos; }}} Search Builder: { title =&gt; { &apos;==&apos; =&gt; { query =&gt; &apos; perl is great &apos;, }}}
  • 161. Text-Query Family Query DSL: { text =&gt; { title =&gt; { query =&gt; &apos; perl great &apos;, type =&gt; &apos;phrase&apos;, slop =&gt; 3 }}} Search Builder: { title =&gt; { &apos;==&apos; =&gt; { query =&gt; &apos; perl great &apos;, slop =&gt; 3 }}}
  • 162. Text-Query Family Query DSL: { text =&gt; { title =&gt; { query =&gt; &apos; perl is gr &apos;, type =&gt; &apos; phrase_prefix &apos;, }}} Search Builder: { title =&gt; { &apos;^&apos; =&gt; { query =&gt; &apos; perl is gr &apos;, }}}
  • 163. Query string / Field Lucene Query Syntax aware “ perl is great”~5 AND author:clint* -deleted
  • 164. Query string / Field Syntax errors: AND perl is great ” author : clint* -
  • 165. Query string / Field Syntax errors: AND perl is great ” author : clint* - ElasticSearch::QueryParser
  • 166. Combining: Bool Query DSL: { bool =&gt; { must =&gt; [ { term =&gt; { foo =&gt; 1}}, ... ], must_not =&gt; [ { term =&gt; { bar =&gt; 1}}, ... ], should =&gt; [ { term =&gt; { X =&gt; 2}}, { term =&gt; { Y =&gt; 2}},... ], minimum_number_should_match =&gt; 1, }}
  • 167. Combining: Bool SearchBuilder: { foo =&gt; 1, bar =&gt; { &apos;!=&apos; =&gt; 1}, -or =&gt; [ X =&gt; 2, Y =&gt; 2], } { -bool =&gt; { must =&gt; { foo =&gt; 1 }, must_not =&gt; { bar =&gt; 1 }, should =&gt; [{ X =&gt; 2}, { Y =&gt; 2 }], minimum_number_should_match =&gt; 1, }}
  • 168. Combining: DisMax Query DSL: { dis_max =&gt; { queries =&gt; [ { term =&gt; { foo =&gt; 1}}, { term =&gt; { bar =&gt; 1}}, ] }} SearchBuilder: { -dis_max =&gt; [ { term =&gt; { foo =&gt; 1}}, { term =&gt; { bar =&gt; 1}}, ], }
  • 169. Bool: combines scores DisMax: uses highest score from all matching clauses
  • 170. Tweaking relevance:
  • 171. Tweaking relevance: Boosting
  • 172. Boosting: at index time { properties =&gt; { content =&gt; { type =&gt; “string” }, title =&gt; { type =&gt; “string” }, }
  • 173. Boosting: at index time { properties =&gt; { content =&gt; { type =&gt; “string” }, title =&gt; { type =&gt; “string”, boost =&gt; 2, }, }, }
  • 174. Boosting: at index time { properties =&gt; { content =&gt; { type =&gt; “string” }, title =&gt; { type =&gt; “string”, boost =&gt; 2, }, rank =&gt; { type =&gt; “integer” }, }, _boost =&gt; { name =&gt; &apos;rank&apos;, null_value =&gt; 1.0 }, }
  • 175. Boosting: at search time Query DSL: { bool =&gt; { should =&gt; [ { text =&gt; { content =&gt; &apos;perl&apos; }}, { text =&gt; { title =&gt; &apos;perl&apos; }}, ] }} SearchBuilder: { content =&gt; &apos;perl&apos;, title =&gt; &apos;perl&apos; }
  • 176. Boosting: at search time Query DSL: { bool =&gt; { should =&gt; [ { text =&gt; { content =&gt; &apos;perl&apos; }}, { text =&gt; { title =&gt; { query =&gt; &apos;perl&apos;, }}, ] }} SearchBuilder: { content =&gt; &apos;perl&apos;, title =&gt; { &apos;=&apos; =&gt; { query =&gt; &apos;perl&apos; }} }
  • 177. Boosting: at search time Query DSL: { bool =&gt; { should =&gt; [ { text =&gt; { content =&gt; &apos;perl&apos; }}, { text =&gt; { title =&gt; { query =&gt; &apos;perl&apos;, boost =&gt; 2 }}, ] }} SearchBuilder: { content =&gt; &apos;perl&apos;, title =&gt; { &apos;=&apos; =&gt; { query =&gt; &apos;perl&apos;, boost=&gt; 2 }} }
  • 178. Boosting: custom_score Query DSL: { custom_score =&gt; { query =&gt; { text =&gt; { title =&gt; &apos;perl&apos; }}, script =&gt; “_score * foo /doc[&apos;rank&apos;].value”, }} SearchBuilder: { -custom_score =&gt; { query =&gt; { title =&gt; &apos;perl&apos; }, script =&gt; “_score * foo /doc[&apos;rank&apos;].value”, }}
  • 179. Query example SearchBuilder: { -or =&gt; [ title =&gt; { &apos;=&apos; =&gt; { query =&gt; &apos;custom score&apos;, boost =&gt; 2 }}, content =&gt; &apos;custom score&apos;, ], -filter =&gt; { repo =&gt; &apos;elasticsearch/elasticsearch&apos;, created_at =&gt; { &apos;&gt;=&apos; =&gt; &apos;2011-07-01&apos;, &apos;&lt;&apos; =&gt; &apos;2011-08-01&apos;}, -or =&gt; [ creator_id =&gt; 123, assignee_id =&gt; 123, ], labels =&gt; [&apos;bug&apos;,&apos;breaking&apos;] } }
  • 180. Query example Query DSL: { query =&gt; { filtered =&gt; { query =&gt; { bool =&gt; { should =&gt; [ { text =&gt; { content =&gt; &amp;quot;custom score&amp;quot; } }, { text =&gt; { title =&gt; { boost =&gt; 2, query =&gt; &amp;quot;custom score&amp;quot; } } }, ], }, }, filter =&gt; { and =&gt; [ { or =&gt; [ { term =&gt; { creator_id =&gt; 123 } }, { term =&gt; { assignee_id =&gt; 123 } }, ]}, { terms =&gt; { labels =&gt; [&amp;quot;bug&amp;quot;, &amp;quot;breaking&amp;quot;] } }, { term =&gt; { repo =&gt; &amp;quot;elasticsearch/elasticsearch&amp;quot; } }, { numeric_range =&gt; { created_at =&gt; { gte =&gt; &amp;quot;2011-07-01&amp;quot;, lt =&gt; &amp;quot;2011-08-01&amp;quot; }}}, ]}, }}
  • 181. &nbsp;
  • 182. https://github.com/clintongormley/GitHubSearch

×