Hi, I’m using 2 references in the links
model:
toAsset: {
type: mongoose.Types.ObjectId,
ref: 'Assets',
index: 'links'
}
fromAsset: {
type: mongoose.Types.ObjectId,
ref: 'Assets',
index: 'links'
},
comment: {
type: String,
index: 'links'
}
Here, toAsset
and fromAsset
both reference a single object each, and the intention is to query 2 fields in the assets
model:
title: {
type: String,
required: true,
index: 'assets'
},
note: {
type: String,
required: true,
index: 'assets'
}
I’m using the following in Node:
const search = {
...(args.phraseToSearchLinks.length > 0 && {
$search: {
index: 'links',
// compound: {
// must: [{
// phrase: {
// query: args.phraseToSearchLinks,
// path: 'comment',
// slop: 2,
// score: { boost: { value: 3 } }
// }
// }]
// },
embeddedDocument: {
path: directionOfLink,
operator: {
compound: {
should: [{
phrase: {
query: args.phraseToSearchLinks,
path: `${directionOfLink}.title`,
slop: 2,
score: { boost: { value: 2 } }
}
},
{
phrase: {
query: args.phraseToSearchLinks,
path: `${directionOfLink}.note`,
slop: 2
}
}]
}
}
}
}
})
}
Here, querying the comment
field returns search results, but I don’t know how to combine it with the embeddedDocument
, which isn’t returning anything at the moment.
I’ve made changes to the index for links
to include the referenced fields, but I’m not seeing results when I perform a search on anything in a title
or note
field:
{
"analyzer": "lucene.standard",
"searchAnalyzer": "lucene.standard",
"mappings": {
"dynamic": false,
"fields": {
"comment": {
"analyzer": "htmlStrippingAnalyzer",
"type": "string"
},
"createdAt": {
"type": "date"
},
"fromAsset": {
"fields": {
"note": {
"analyzer": "htmlStrippingAnalyzer",
"searchAnalyzer": "htmlStrippingAnalyzer",
"type": "string"
},
"title": {
"analyzer": "lucene.standard",
"multi": {
"keywordAnalyzer": {
"analyzer": "ngramShingler",
"searchAnalyzer": "ngramShingler",
"type": "string"
}
},
"searchAnalyzer": "lucene.standard",
"type": "string"
}
},
"type": "embeddedDocuments"
},
"isActive": {
"type": "boolean"
},
"toAsset": {
"fields": {
"note": {
"analyzer": "htmlStrippingAnalyzer",
"searchAnalyzer": "htmlStrippingAnalyzer",
"type": "string"
},
"title": {
"analyzer": "lucene.standard",
"multi": {
"keywordAnalyzer": {
"analyzer": "ngramShingler",
"searchAnalyzer": "ngramShingler",
"type": "string"
}
},
"searchAnalyzer": "lucene.standard",
"type": "string"
}
},
"type": "embeddedDocuments"
},
"updatedAt": {
"type": "date"
}
}
},
"analyzers": [
{
"name": "ngramShingler",
"tokenFilters": [
{
"maxShingleSize": 3,
"minShingleSize": 2,
"type": "shingle"
}
],
"tokenizer": {
"maxGram": 5,
"minGram": 2,
"type": "nGram"
}
},
{
"charFilters": [
{
"ignoredTags": [
"a",
"div",
"p",
"strong",
"em",
"img",
"figure",
"figcaption",
"ol",
"ul",
"li",
"span"
],
"type": "htmlStrip"
}
],
"name": "htmlStrippingAnalyzer",
"tokenFilters": [],
"tokenizer": {
"type": "standard"
}
}
]
}
At this stage, I’m not certain if what I’m attempting is possible! Any advice would be excellent.