Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var PageSchema = new Schema({
- nr: { type: Number, required: true },
- content: { type: String }
- });
- var DocumentSchema = new Schema({
- created: { type: Date, default: Date.now },
- tags: [{ type: ObjectId, ref: "Tag" }],
- pages: { type: [PageSchema], es_indexed: true, es_type: "nested", es_include_in_parent: true }
- });
- DocumentSchema.plugin(mongoosastic);
- var Document = mongoose.model('Document', DocumentSchema);
- Document.search({
- multi_match: {
- fields: ["pages.content"],
- query: "oneone",
- fuzziness: "AUTO"
- }
- }, function(err, results) {
- if (err) return next(err);
- res.json(results);
- });
- {
- "_shards": {
- "failed": 0,
- "successful": 5,
- "total": 5
- },
- "hits": {
- "hits": [
- {
- "_id": "5881d37a6e20aa66af14168c",
- "_index": "documents",
- "_score": 0.2876821,
- "_source": {
- "pages": [
- {
- "content": "page oneone",
- "nr": 1
- },
- {
- "content": "page twotwo",
- "nr": 2
- }
- ]
- },
- "_type": "document"
- }
- ],
- "max_score": 0.2876821,
- "total": 1
- },
- "timed_out": false,
- "took": 3
- }
- "pages": [
- {
- "content": "page oneone",
- "nr": 1
- }
- ]
- "pages": [
- {
- "content": "page oneone",
- "nr": 1
- },
- {
- "content": "page twotwo",
- "nr": 2
- }
- ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement