I would like to create a new property to the propertybag. And it needs to be indexed by search. I try this but it is not working:
private void CreatePropertyBagItem(Web web, string key, string value)
{
web.Context.Load(web, w => w.AllProperties);
//Execute query
web.Context.ExecuteQuery();
//set property bag
web.AddIndexedPropertyBagKey(key);
web.AllProperties[key] = value;
//Update and write back to web
web.Update();
web.Context.ExecuteQuery();
}
When I remove the row with "AddIndexedPropertyBagKey" it creates successfully a new property in the propertybag, but it is not indexed.
ps. I try to do this in CSOM code.