Vishal_Chauhan

Fetch records with Group by with Completion Suggester

Dec 11th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.00 KB | None | 0 0
  1. {
  2. "XYZ": {
  3. "mappings": {
  4. "properties": {
  5. "customerInfo": {
  6. "properties": {
  7. "emailList": {
  8. "type": "text",
  9. "fields": {
  10. "keyword": {
  11. "type": "keyword"
  12. }
  13. }
  14. },
  15. "id": {
  16. "type": "text",
  17. "fields": {
  18. "completion": {
  19. "type": "completion",
  20. "analyzer": "standard",
  21. "preserve_separators": true,
  22. "preserve_position_increments": true,
  23. "max_input_length": 50,
  24. "contexts": [
  25. {
  26. "name": "mailboxIdStr",
  27. "type": "CATEGORY",
  28. "path": "mailboxIdStr"
  29. }
  30. ]
  31. },
  32. "keyword": {
  33. "type": "keyword"
  34. }
  35. }
  36. },
  37. "name": {
  38. "type": "text",
  39. "fields": {
  40. "completion": {
  41. "type": "completion",
  42. "analyzer": "simple",
  43. "preserve_separators": true,
  44. "preserve_position_increments": true,
  45. "max_input_length": 50,
  46. "contexts": [
  47. {
  48. "name": "mailboxIdStr",
  49. "type": "CATEGORY",
  50. "path": "mailboxIdStr"
  51. }
  52. ]
  53. },
  54. "keyword": {
  55. "type": "keyword"
  56. }
  57. },
  58. "fielddata": true
  59. }
  60. }
  61. }
  62. }
  63. }
  64. }
  65. }
  66.  
  67.  
  68. As per above mapping I'm making request something like this.
  69. {
  70. "suggest": {
  71. "subject_suggest": {
  72. "prefix": "t",
  73. "completion": {
  74. "field": "customerInfo.name.completion",
  75. "size": 3,
  76. "contexts": {
  77. "mailboxIdStr": [
  78. 770,
  79. 854,
  80. 901,
  81. 902
  82. ]
  83. }
  84. }
  85. }
  86. }
  87. }
  88.  
  89.  
  90. It gives me response something like this.
  91.  
  92. {
  93. "suggest": {
  94. "subject_suggest": [
  95. {
  96. "text": "John",
  97. "offset": 0,
  98. "length": 1,
  99. "options": [
  100. {
  101. "text": "The G",
  102. "_index": "conversations",
  103. "_type": "_doc",
  104. "_id": "CxTc6W4Bk0d_pHk3pEIX",
  105. "_score": 1.0,
  106. "_source": {
  107. "customerInfo": {
  108. "id": "1",
  109. "name": "John",
  110. "emailList": "test@gmail.com"
  111. }
  112. }
  113. },
  114. {
  115. "text": "The G",
  116. "_index": "conversations",
  117. "_type": "_doc",
  118. "_id": "DhTc6W4Bk0d_pHk3pEIX",
  119. "_score": 1.0,
  120. "_source": {
  121. "customerInfo": {
  122. "id": "1",
  123. "name": "John",
  124. "emailList": "test@gmail.com"
  125. }
  126. }
  127. },
  128. {
  129. "text": "The G",
  130. "_index": "conversations",
  131. "_type": "_doc",
  132. "_id": "FRTc6W4Bk0d_pHk3pEIX",
  133. "_score": 1.0,
  134. "_source": {
  135. "customerInfo": {
  136. "id": "2",
  137. "name": "John",
  138. "emailList": "testing@google.com"
  139. }
  140. }
  141. }
  142. ]
  143. }
  144. ]
  145. }
  146. }
  147.  
  148. In response i got dublicate records.
  149. It gives me 2 dublicate records --> id: 1 and name:John.
  150. In actual result name can be same but it should have unique id.
  151. My expected output is as per below.
  152.  
  153.  
  154. {
  155. "suggest": {
  156. "subject_suggest": [
  157. {
  158. "text": "John",
  159. "offset": 0,
  160. "length": 1,
  161. "options": [
  162. {
  163. "text": "The G",
  164. "_index": "testconversations",
  165. "_type": "_doc",
  166. "_id": "DhTc6W4Bk0d_pHk3pEIX",
  167. "_score": 1.0,
  168. "_source": {
  169. "customerInfo": {
  170. "id": "1",
  171. "name": "John",
  172. "emailList": "test@gmail.com"
  173. }
  174. }
  175. },
  176. {
  177. "text": "The G",
  178. "_index": "testconversations",
  179. "_type": "_doc",
  180. "_id": "FRTc6W4Bk0d_pHk3pEIX",
  181. "_score": 1.0,
  182. "_source": {
  183. "customerInfo": {
  184. "id": "2",
  185. "name": "John",
  186. "emailList": "testing@gmail.com"
  187. }
  188. }
  189. }
  190. ]
  191. }
  192. ]
  193. }
  194. }
  195.  
  196. So i'm stuck here how to get this type of result.
Add Comment
Please, Sign In to add comment