简体   繁体   中英

Unable to search inserted Documents in Elastic Search Node

I have Set up a elastic search node on Azure and Implemented CRUD operations for the same using nest client while i have no problem inserting a new document in to the node but the inserted document is not visible for search though it can be seen in elasticsearch head in chrome extensions.

I have gone through documentation which suggest me to refresh the index after inserting yet no success in getting the inserted document in search results

public bool AddNewProductEL( string indexName, ProductTable product)
    {
        bool status = false;
        try
        {
            List<ProductTable> FinalList = new List<ProductTable>();
            ProductTable item = new ProductTable();
            item.ProductID = product.ProductID;
            item.ProductName = product.ProductName;
            string packing = (from t in entity.Packings where t.PackingID == product.PackingFID select t.PackingName).FirstOrDefault();
            item.PackingName = packing == null ? "" : packing;
            string manu = (from t in entity.Manufacturers where t.ManufacturerID == product.ManufacturerFID select t.ManufacturerName).FirstOrDefault();
            item.Manufacturername = manu == null ? "" : manu;
            item.ProductDescription = product.ProductDescription == null ? "" : product.ProductDescription;
            string brand = (from t in entity.Brands where t.BrandID == product.BrandFID select t.BrandName).FirstOrDefault();
            item.Brandname = brand == null ? "" : brand;
            item.ProductTypeFID = product.ProductTypeFID;
            FinalList.Add(item);

            foreach (var dt in FinalList)
            {                  
                var response = elasticClient.Index(dt, i => i
              .Index(indexName)
              .Type(TypeName.From<ProductTable>())
              .Id(dt.ProductID)
              .Refresh(Refresh.True));
                if (response.IsValid) { status = true; }
                var r = elasticClient.RefreshAsync(indexName);            
            }
           // System.Web.HttpContext.Current.Response.Write(" inserting product in elasticsearch status : - " + status);
            return status;
        }
        catch (Exception e)
        {
            status = false;
          //  System.Web.HttpContext.Current.Response.Write("error inserting product in elasticsearch : - " + e.Message + " inner exception :-" + e.InnerException);
            return status;
        }
    }

共享您的映射,您可能有可能禁用了您尝试搜索文档的字段的索引。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM