Hi, I am unable to map the ElasticsearchClient
SearchASync
result into my data model. Gotten a conversion error:
The server encountered an error processing the request. Please see the [service help page] for constructing valid requests to the service. The exception message is 'The JSON value could not be converted to System.String. Path: $.body | LineNumber: 0 | BytePositionInLine: 224.
Below are my code snippets:
namespace Model
{
public class ElasticsearchDocs
{
public string Id { get; set; }
public string Title { get; set; }
public string Url { get; set; }
public string Body { get; set; }
}
}
public async Task<ElasticsearchDocs> SearchDocumentsByContent()
{
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
var settings = new ElasticsearchClientSettings(new Uri("https://localhost:9200"))
.CertificateFingerprint("795b709a3a0f70ee69f12320a5d73c49c2465a5dfcf4e1c13a928cef4c6e6c2e")
.Authentication(new BasicAuthentication("<USERNAME>", "<PASSWORD>"));
var client = new ElasticsearchClient(settings);
ElasticsearchDocs esDocs = new ElasticsearchDocs();
var request = new SearchRequest("search-ocr-poc")
{
Query = new MatchAllQuery()
};
var response = await client.SearchAsync<ElasticsearchDocs>(request);
if (response.IsValidResponse)
{
esDocs = response.Documents.FirstOrDefault();
}
return esDocs;
}
not sure if need to manually map the field to data model.
Do i need to reindex my index ?
I already have my index created during the Elasticsearch connector processor.
This is my output when i use the command
GET /search-ocr-poc/_search
{
"query": {
"match_all": {}
}
}
{
"took": 21,
"timed_out": false,
"_shards": {
"total": 2,
"successful": 2,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 69,
"relation": "eq"
},
"max_score": 1,
"hits": [
{
"_index": "search-ocr-poc",
"_id": "ae7be893-6ced-4b0c-9230-b6bc168dcddd",
"_score": 1,
"_source": {
"creation_time": "2023-12-26T13:55:14Z",
"file_name": "",
"editor_id": 1073741823,
"type": "list_item",
"title": "All Draft Documents",
"url": "/sites/COPS/Reports%20List/DispForm.aspx?ID=5&Source=/sites/COPS/Reports%20List/AllItems.aspx&ContentTypeId=0x01009EC04F25E7BD464D9978DF8AB3448A9D",
"size": 0,
"id": "ae7be893-6ced-4b0c-9230-b6bc168dcddd",
"author_id": 1073741823,
"_timestamp": "2023-12-26T13:55:14Z"
}
},
{
"_index": "search-ocr-poc",
"_id": "d4e860fd-8688-442b-a4b1-756dedb29397",
"_score": 1,
"_source": {
"creation_time": "2023-12-26T13:56:16Z",
"server_relative_url": "/sites/COPS/Documents",
"parent_web_url": "/sites/COPS",
"id": "d4e860fd-8688-442b-a4b1-756dedb29397",
"type": "document_library",
"title": "Documents",
"_timestamp": "2024-04-15T08:10:57Z",
"url": "/sites/COPS/Documents"
}
}
]
}
}