-
Using ingest-attachment plugin.
-
Elasticsearch version: 5.5.1
-
NEST: 5.5
-
My goal is to be able to search the Content of a list of documents called PersonDocuments attached to IndexablePersonModel, and return the persons that have documents that contain the query term.
-
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.
-
How do I query on the PersonDocuments?
-
Here is the query that I have so far:
QueryContainer Query(QueryContainerDescriptor < IndexablePersonModel > q) {
var returnQuery = q
.Match(m => m
.Field(a => a.PersonDocuments.FirstOrDefault().Content)
.Boost(SearchConstants.Boosts.XXXLarge)
.Query(Form.Query))
|| q.FunctionScore(fs => fs
.MaxBoost(SearchConstants.Boosts.Large)
.Functions(ff => ff
.FieldValueFactor(fvf => fvf
.Field(p => p...)
.Factor(0.0001)))
.Query(query => query
.MultiMatch(m => m
.Fields(f => f...)
.Operator(Operator.And)
.Query(Form.Query))));
return returnQuery;
}
- The line with the problem is:
.Field(a => a.PersonDocuments.FirstOrDefault().Content)
-
I don't know how to loop through the list PersonDocuments.
-
The following is the index that I created on persons:
{
"person-index": {
"mappings": {
"person": {
"properties": {
"name": {
"type": "text",
"fields": {
"keyword": {
"type": "text",
"analyzer": "person-name-keyword"
},
"raw": {
"type": "keyword"
}
},
"analyzer": "person-name-analyzer"
},
"personDocuments": {
"type": "nested",
"properties": {
"attachment": {
"properties": {
"author": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"content": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"content_length": {
"type": "long"
},
"content_type": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"date": {
"type": "date"
},
"detect_language": {
"type": "boolean"
},
"indexed_chars": {
"type": "long"
},
"keywords": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"language": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"name": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"title": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
},
"content": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"id": {
"type": "integer"
},
"name": {
"type": "text",
"analyzer": "document-path-analyzer"
},
"path": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
}
}
},
"settings": {
...
}
}
}