我已经在Azure上设置了一个弹性搜索节点,并使用嵌套客户端对其进行了相同的CRUD操作,而我可以将新文档插入该节点没有问题,但是虽然可以看到插入的文档,但对于搜索来说是不可见的在chrome扩展程序的elasticsearch头中。
我浏览了一些文档,这些文档建议我在插入后刷新索引,但仍无法成功将插入的文档显示在搜索结果中
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;
}
}
答案 0 :(得分:0)
共享您的映射,有可能您为试图搜索文档的字段禁用了索引。