-
My goal is to be able to perform a search on the Content of a list of documents called PersonDocuments attached to IndexablePersonModel, and return the persons that have documents that contain the query term.
-
The query that I'm using is returning the respective persons ONLY IF the query term matches EXACTLY the WHOLE content of the attached document. But if I search only for one word in the document, nothing is returned. Please advise.
-
Using ingest-attachment plugin.
-
Elasticsearch version: 5.5.1
-
NEST: 5.5
-
PersonDocuments is a list of IndexablePersonDocument on the IndexablePersonModel
public IEnumerable<IndexablePersonDocument> PersonDocuments { get; set; }
-
And one of the attributes of IndexablePersonDocument is string Content.
-
Here is the query that I have so far:
protected override QueryContainer Query(QueryContainerDescriptor<IndexablePersonModel> q)
{
var returnQuery = q
.Match(m => m
.Field(p => p.Name.Suffix(SearchConstants.Keyword))
.Boost(SearchConstants.Boosts.XXLarge)
.Query(Form.Query)
)
|| q.Nested(n => n
.Boost(SearchConstants.Boosts.XXXLarge)
.InnerHits(i => i.Explain())
.Path(p => p.PersonDocuments)
.Query(nq => +nq
.Bool(b => b
.Should(
s => s.Term(p => p.PersonDocuments.First().Attachment.Content.Suffix(SearchConstants.Keyword), Form.Query)
).MinimumShouldMatch(MinimumShouldMatch.Fixed(1))
)
)
.IgnoreUnmapped()
)
|| q.FunctionScore(fs => fs
.MaxBoost(SearchConstants.Boosts.Large)
.Functions(ff => ff
.FieldValueFactor(fvf => fvf
.Field(p => p.TotalPurchasedQuantity)
.Factor(0.0001)
)
)
.Query(query => query
.MultiMatch(m => m
.Fields(f => f
.Field(p => p.Name, SearchConstants.Boosts.XSmall)
.Field(p => p.PersonDocuments.First().Attachment.Content, SearchConstants.Boosts.XXLarge)
)
.Operator(Operator.And)
.Query(Form.Query)
)
)
)
#endregion
;
return returnQuery;
}