Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Rosa 17 posts 121 karma points
    Apr 01, 2021 @ 14:10
    Rosa
    0

    Elasticsearch and Umbraco 8 - recommendations for integrating

    Hi there,

    I'm working on a digital asset management solution where admin users will be able to upload into umbraco custom document types of type 'Asset' (could be video, image, copy etc) with a variety of property fields. There will likely be thousands of these uploaded to Umbraco once the site is live.

    Users of the site need to be able to search for assets quickly using a variety of criteria (tags, categories, title, description, asset type etc). I've determined that Elasticsearch may be a great fit for these use cases but I'm finding it tricky to know where to start in hooking them up.

    My main questions are:

    • Is it best to download Elasticsearch onto my computer or to use the cloud solution? (aware that is probably extremely n00bish)
    • I am assuming that everytime a document type of type 'Asset' is created/updated/deleted, I need to ping Elasticsearch with the updated data - where would this happen in the code? Would it happen in the Umbraco code itself?

    Any other thoughts/recommendations/examples of implementation would be EXTREMELY appreciated!

    Many thanks, Rosa

  • iNETZO 133 posts 496 karma points c-trib
    Apr 05, 2021 @ 10:04
    iNETZO
    1

    Hi Rosa,

    We're using the great package for ElasticSearch made by Novicell https://www.nuget.org/packages/Novicell.Examine.ElasticSearch/

    https://github.com/Novicell/Novicell.Examine.ElasticSearch/wiki/Installation

    This replaces the default Examine search engine and handles all created / updated / deleted actions to your Elastic-instance for you.

    We're using a local install for development and production but technically it doesn't matter that much i guess. We just like to keep the data to ourselfs.

    Best regards,

    iNETZO

  • Rosa 17 posts 121 karma points
    Apr 07, 2021 @ 09:47
    Rosa
    0

    Hi!

    Thanks so much for this. I have the plugin working and am running elastic search and kibana. But now I am wondering how I map a document type in umbraco to a document within elastic search.. is this possible?

    So that users can use a search bar on my site to find a certain 'Product' lets say?

    Kind regards, Rosa

  • iNETZO 133 posts 496 karma points c-trib
    Apr 07, 2021 @ 19:18
    iNETZO
    1

    Hi,

    You can do a search with the regular Nest.ElasticClient. For example:

    using Nest;
    using Novicell.Examine.ElasticSearch.Model;
    
                int page = 1;
                int amountPerPage = 20;      
                string search = "texttosearchfor";
    
                var settings = new ConnectionSettings(new 
    
            Uri(System.Configuration.ConfigurationManager.AppSettings["examine:ElasticSearch["externalindex"].Url"].ToString())).DefaultIndex("externalindex");
                    var client = new ElasticClient(settings);
    
                    SearchDescriptor<Document> searchDescriptor = new SearchDescriptor<Document>();
    
                    searchDescriptor.Index("externalindex")
                        .Take(amountPerPage)
                        .Skip(amountPerPage * (page - 1))
                        .Query(q => q
                                           .Bool(b => b
                                               .Must(mu => mu
                                                    .MultiMatch(qs => qs
                                                        .Query(search).Type(TextQueryType.PhrasePrefix)
                                                        .Fields(fs => fs
                                                            .Field("nodeName") // List of properties where you want to search in
                                                            .Field("otherfield1")
                                                            .Field("otherfield2")
                                                        )
                                                    ),
                                                    mu => mu
                                                   .QueryString(qs => qs
                                                       .Query("Asset") // Search for nodes of type 'Asset'
                                                       .Fields(fs => fs
                                                           .Field("__NodeTypeAlias")
                                                       )
                                                   )
                                               )
                                           )
                                       )
                                       .Sort(s => s.Asending("nodeName"));
    
                    //Generate search results
                    var results = client.Search<Document>(searchDescriptor);
    
                    if (results != null && results.Documents.Any())
                    {
                          foreach(var document in results.Documents) {
                              // Use the Umbraco helper to load the document by Id
                              var node = Umbraco.Content(int.Parse(document["Id"].ToString()) );
                          }
                    }
    

    I haven't tested so maybe it contains errors or typos but you'll get the idea i guess. Check the documentation for better explanation https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/nest-getting-started.html

    Best regards,

    iNETZO

  • Rosa 17 posts 121 karma points
    Apr 08, 2021 @ 08:02
    Rosa
    0

    Oh amazing! Thank you so much!!!

Please Sign in or register to post replies

Write your reply to:

Draft