20_search.yaml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  1. # Integration tests for Lang JavaScript components
  2. #
  3. "JavaScript Query":
  4. - do:
  5. index:
  6. index: test
  7. type: test
  8. id: 1
  9. body: { "test": "value beck", "num1": 1.0 }
  10. - do:
  11. index:
  12. index: test
  13. type: test
  14. id: 2
  15. body: { "test": "value beck", "num1": 2.0 }
  16. - do:
  17. index:
  18. index: test
  19. type: test
  20. id: 3
  21. body: { "test": "value beck", "num1": 3.0 }
  22. - do:
  23. indices.refresh: {}
  24. - do:
  25. index: test
  26. search:
  27. body:
  28. query:
  29. script:
  30. script:
  31. inline: "doc['num1'].value > 1"
  32. lang: js
  33. script_fields:
  34. sNum1:
  35. lang: js
  36. script: "doc['num1'].value"
  37. sort:
  38. num1:
  39. order: asc
  40. - match: { hits.total: 2 }
  41. - match: { hits.hits.0.fields.sNum1.0: 2.0 }
  42. - match: { hits.hits.1.fields.sNum1.0: 3.0 }
  43. - do:
  44. index: test
  45. search:
  46. body:
  47. query:
  48. script:
  49. script:
  50. inline: "doc['num1'].value > param1"
  51. lang: js
  52. params:
  53. param1: 1
  54. script_fields:
  55. sNum1:
  56. lang: js
  57. script: "doc['num1'].value"
  58. sort:
  59. num1:
  60. order: asc
  61. - match: { hits.total: 2 }
  62. - match: { hits.hits.0.fields.sNum1.0: 2.0 }
  63. - match: { hits.hits.1.fields.sNum1.0: 3.0 }
  64. - do:
  65. index: test
  66. search:
  67. body:
  68. query:
  69. script:
  70. script:
  71. inline: "doc['num1'].value > param1"
  72. lang: js
  73. params:
  74. param1: -1
  75. script_fields:
  76. sNum1:
  77. lang: js
  78. script: "doc['num1'].value"
  79. sort:
  80. num1:
  81. order: asc
  82. - match: { hits.total: 3 }
  83. - match: { hits.hits.0.fields.sNum1.0: 1.0 }
  84. - match: { hits.hits.1.fields.sNum1.0: 2.0 }
  85. - match: { hits.hits.2.fields.sNum1.0: 3.0 }
  86. ---
  87. "JavaScript Script Field Using Source":
  88. - do:
  89. index:
  90. index: test
  91. type: test
  92. id: 1
  93. body: {
  94. "obj1": {
  95. "test": "something"
  96. },
  97. "obj2": {
  98. "arr2": [ "arr_value1", "arr_value2" ]
  99. }
  100. }
  101. - do:
  102. indices.refresh: {}
  103. - do:
  104. index: test
  105. search:
  106. body:
  107. script_fields:
  108. s_obj1:
  109. lang: js
  110. script: "_source.obj1"
  111. s_obj1_test:
  112. lang: js
  113. script: "_source.obj1.test"
  114. s_obj2:
  115. lang: js
  116. script: "_source.obj2"
  117. s_obj2_arr2:
  118. lang: js
  119. script: "_source.obj2.arr2"
  120. - match: { hits.total: 1 }
  121. - match: { hits.hits.0.fields.s_obj1.0.test: something }
  122. - match: { hits.hits.0.fields.s_obj1_test.0: something }
  123. - match: { hits.hits.0.fields.s_obj2.0.arr2.0: arr_value1 }
  124. - match: { hits.hits.0.fields.s_obj2.0.arr2.1: arr_value2 }
  125. - match: { hits.hits.0.fields.s_obj2_arr2.0: arr_value1 }
  126. - match: { hits.hits.0.fields.s_obj2_arr2.1: arr_value2 }
  127. ---
  128. "JavaScript Custom Script Boost":
  129. - do:
  130. index:
  131. index: test
  132. type: test
  133. id: 1
  134. body: { "test": "value beck", "num1": 1.0 }
  135. - do:
  136. index:
  137. index: test
  138. type: test
  139. id: 2
  140. body: { "test": "value beck", "num1": 2.0 }
  141. - do:
  142. indices.refresh: {}
  143. - do:
  144. index: test
  145. search:
  146. body:
  147. query:
  148. function_score:
  149. query:
  150. term:
  151. test: value
  152. "functions": [{
  153. "script_score": {
  154. "script": {
  155. "lang": "js",
  156. "inline": "doc['num1'].value"
  157. }
  158. }
  159. }]
  160. - match: { hits.total: 2 }
  161. - match: { hits.hits.0._id: "2" }
  162. - match: { hits.hits.1._id: "1" }
  163. - do:
  164. index: test
  165. search:
  166. body:
  167. query:
  168. function_score:
  169. query:
  170. term:
  171. test: value
  172. "functions": [{
  173. "script_score": {
  174. "script": {
  175. "lang": "js",
  176. "inline": "-doc['num1'].value"
  177. }
  178. }
  179. }]
  180. - match: { hits.total: 2 }
  181. - match: { hits.hits.0._id: "1" }
  182. - match: { hits.hits.1._id: "2" }
  183. - do:
  184. index: test
  185. search:
  186. body:
  187. query:
  188. function_score:
  189. query:
  190. term:
  191. test: value
  192. "functions": [{
  193. "script_score": {
  194. "script": {
  195. "lang": "js",
  196. "inline": "Math.pow(doc['num1'].value, 2)"
  197. }
  198. }
  199. }]
  200. - match: { hits.total: 2 }
  201. - match: { hits.hits.0._id: "2" }
  202. - match: { hits.hits.1._id: "1" }
  203. - do:
  204. index: test
  205. search:
  206. body:
  207. query:
  208. function_score:
  209. query:
  210. term:
  211. test: value
  212. "functions": [{
  213. "script_score": {
  214. "script": {
  215. "lang": "js",
  216. "inline": "Math.max(doc['num1'].value, 1)"
  217. }
  218. }
  219. }]
  220. - match: { hits.total: 2 }
  221. - match: { hits.hits.0._id: "2" }
  222. - match: { hits.hits.1._id: "1" }
  223. - do:
  224. index: test
  225. search:
  226. body:
  227. query:
  228. function_score:
  229. query:
  230. term:
  231. test: value
  232. "functions": [{
  233. "script_score": {
  234. "script": {
  235. "lang": "js",
  236. "inline": "doc['num1'].value * _score"
  237. }
  238. }
  239. }]
  240. - match: { hits.total: 2 }
  241. - match: { hits.hits.0._id: "2" }
  242. - match: { hits.hits.1._id: "1" }
  243. - do:
  244. index: test
  245. search:
  246. body:
  247. query:
  248. function_score:
  249. query:
  250. term:
  251. test: value
  252. "functions": [{
  253. "script_score": {
  254. "script": {
  255. "lang": "js",
  256. "inline": "param1 * param2 * _score",
  257. "params": {
  258. "param1": 2,
  259. "param2": 2
  260. }
  261. }
  262. }
  263. }]
  264. - match: { hits.total: 2 }
  265. ---
  266. "JavaScript Scores Nested":
  267. - do:
  268. index:
  269. index: test
  270. type: test
  271. id: 1
  272. body: { "dummy_field": 1 }
  273. - do:
  274. indices.refresh: {}
  275. - do:
  276. index: test
  277. search:
  278. body:
  279. query:
  280. function_score:
  281. query:
  282. function_score:
  283. "functions": [
  284. {
  285. "script_score": {
  286. "script": {
  287. "lang": "js",
  288. "inline": "1"
  289. }
  290. }
  291. }, {
  292. "script_score": {
  293. "script": {
  294. "lang": "js",
  295. "inline": "_score.doubleValue()"
  296. }
  297. }
  298. }
  299. ]
  300. "functions": [{
  301. "script_score": {
  302. "script": {
  303. "lang": "js",
  304. "inline": "_score.doubleValue()"
  305. }
  306. }
  307. }]
  308. - match: { hits.total: 1 }
  309. - match: { hits.hits.0._score: 1.0 }
  310. ---
  311. "JavaScript Scores With Agg":
  312. - do:
  313. index:
  314. index: test
  315. type: test
  316. id: 1
  317. body: { "dummy_field": 1 }
  318. - do:
  319. indices.refresh: {}
  320. - do:
  321. index: test
  322. search:
  323. body:
  324. query:
  325. function_score:
  326. "functions": [{
  327. "script_score": {
  328. "script": {
  329. "lang": "js",
  330. "inline": "_score.doubleValue()"
  331. }
  332. }
  333. }]
  334. aggs:
  335. score_agg:
  336. terms:
  337. script:
  338. lang: js
  339. inline: "_score.doubleValue()"
  340. - match: { hits.total: 1 }
  341. - match: { hits.hits.0._score: 1.0 }
  342. - match: { aggregations.score_agg.buckets.0.key: "1.0" }
  343. - match: { aggregations.score_agg.buckets.0.doc_count: 1 }
  344. ---
  345. "JavaScript Use List Length In Scripts":
  346. - do:
  347. index:
  348. index: test
  349. type: test
  350. id: 1
  351. body: { "f": 42 }
  352. - do:
  353. indices.refresh: {}
  354. - do:
  355. index: test
  356. search:
  357. body:
  358. script_fields:
  359. foobar:
  360. lang: js
  361. script: "doc['f'].values.length"
  362. - match: { hits.total: 1 }
  363. - match: { hits.hits.0.fields.foobar.0: 1 }