Advertisement
Guest User

Untitled

a guest
Jan 20th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. var PageSchema = new Schema({
  2. nr: { type: Number, required: true },
  3. content: { type: String }
  4. });
  5.  
  6. var DocumentSchema = new Schema({
  7. created: { type: Date, default: Date.now },
  8. tags: [{ type: ObjectId, ref: "Tag" }],
  9. pages: { type: [PageSchema], es_indexed: true, es_type: "nested", es_include_in_parent: true }
  10. });
  11.  
  12. DocumentSchema.plugin(mongoosastic);
  13.  
  14. var Document = mongoose.model('Document', DocumentSchema);
  15.  
  16. Document.search({
  17. multi_match: {
  18. fields: ["pages.content"],
  19. query: "oneone",
  20. fuzziness: "AUTO"
  21. }
  22. }, function(err, results) {
  23. if (err) return next(err);
  24. res.json(results);
  25. });
  26.  
  27. {
  28. "_shards": {
  29. "failed": 0,
  30. "successful": 5,
  31. "total": 5
  32. },
  33. "hits": {
  34. "hits": [
  35. {
  36. "_id": "5881d37a6e20aa66af14168c",
  37. "_index": "documents",
  38. "_score": 0.2876821,
  39. "_source": {
  40. "pages": [
  41. {
  42. "content": "page oneone",
  43. "nr": 1
  44. },
  45. {
  46. "content": "page twotwo",
  47. "nr": 2
  48. }
  49. ]
  50. },
  51. "_type": "document"
  52. }
  53. ],
  54. "max_score": 0.2876821,
  55. "total": 1
  56. },
  57. "timed_out": false,
  58. "took": 3
  59. }
  60.  
  61. "pages": [
  62. {
  63. "content": "page oneone",
  64. "nr": 1
  65. }
  66. ]
  67.  
  68. "pages": [
  69. {
  70. "content": "page oneone",
  71. "nr": 1
  72. },
  73. {
  74. "content": "page twotwo",
  75. "nr": 2
  76. }
  77. ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement