我們有一個系統,客戶可以在其中將新欄位添加到 xml 檔案中的索引映射中。發生這種情況時,我們將獲取 xml 檔案并基于它在搜索引擎中創建索引。這是我們需要支持的遺留要求。
所以如果用戶上傳xml檔案
<Group name="some group">
<Member field="description" type="text"/>
<Member field="name" type="Date"/>
</Group>
我需要能夠呼叫 ElastiSearch 來創建這樣的索引映射。
PUT /my-index-000001
{
"mappings": {
"properties": {
"description": { "type": "integer" },
"name": { "type": "date" }
}
}
}
現在的問題是我不確定如何在 .NET 客戶端中執行此操作,因為它是強型別的。
我需要創建一個類并呼叫 Create 方法來完成它。
client.Indices.Create("my-index-000001", c => c
.Map<SomeClass>(m => m
.AutoMap<SomeClass>()
)
現在這是我不能做的事情,因為我不知道 xml 檔案中將存在什么樣的屬性。
還有其他方法嗎?也許有某種索引類的構建器?
uj5u.com熱心網友回復:
我只是將 XML 轉換為Dictionary<PropertyName, IProperty>并在方法中使用它client.Indices.PutMappingAsync來更新索引定義,例如
var request = new PutMappingRequest("test")
{
Properties = new Properties(new Dictionary<PropertyName, IProperty>
{
{ "field1", new TextProperty { Name = fieldName, Analyzer = "standard" } }
})
};
await client.Indices.PutMappingAsync(request);
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/498383.html
