Epinova / Epinova.Elasticsearch

A search-plugin for Episerver CMS and Commerce
MIT License
29 stars 20 forks source link

Index custom type error #172

Closed jimiee closed 1 year ago

jimiee commented 2 years ago

I'm trying to index a custom type but are getting an error that is found in BulkBatchResult (using v11.7.3): Status: 400 Error: Invalid type: expecting [Epinova_ElasticSearch_Core_models-IndexItem] but got [CustomDocument]

I'm using the code from under the section named "Custom types (non-Episerver content)" in the documentation: https://github.com/Epinova/Epinova.Elasticsearch#user-content-custom-types-non-episerver-content

otanum commented 2 years ago

Please upgrade to latest version (v11.7.4.240)

jimiee commented 2 years ago

I've upgraded to the latest version now but i'm still getting the same error message.

otanum commented 2 years ago

You have created a new ScheduledPlugIn for indexing CustomDocument?

otanum commented 2 years ago

You can try to call something like this with your ScheduledPlugin


public void Index(List<CustomDocument> documents, out string errorMessage, out int indexed, out int bulkErrors)
{
  errorMessage = string.Empty;
  indexed = 0;
  bulkErrors = 0;
  string indexName = GetYourCustomDocumentIndexWithLanguage();

  BulkOperation[] bulkOperations = documents.Select(d => new BulkOperation(indexName, d, <id???>)).ToArray();
  _indexer.Service.UpdateMapping(typeof(CustomDocument), typeof(CustomDocument), indexName, <language>, false);
  BulkBatchResult bulkResult = _indexer.Service.Bulk(bulkOperations);

  foreach (BulkResult item in bulkResult.Batches)
  {
    if (!item.Errors)
    {
      indexed += item.Items.Length;
    }
    else
    {
      IEnumerable<string> errors = item.Items.Where(i => !string.IsNullOrWhiteSpace(i.Error?.Reason)).Select(i => i.Error.Reason);
      errorMessage = string.Concat(errorMessage, " ", string.Join(" ", errors));
      bulkErrors++;
    }
  }
}
otanum commented 1 year ago

No feedback