1
創造彈性搜索的多態性數據的索引我有如何使用NEST
var descriptor = new CreateIndexDescriptor("resources")
.Mappings(ms => ms
.Map<ResourceEntity>(m => m
.AutoMap()
.RoutingField(k => k.Required(true))
.Properties(props => props
.Keyword(s1 => s1.Name(p => p.Id).Norms(false))
.Keyword(k => k.Name(p => p.Type).Norms(false))
.Keyword(k => k.Name(p => p.Location).Norms(false))
)
)
.Map<StreamEntity>(m => m
.AutoMap()
.RoutingField(r => r.Required(true))
.Properties(props => props
.Keyword(s1 => s1.Name(p => p.Name).Norms(false))
)
)
.Map<StreamMessageEntity>(m => m
.AutoMap()
.Parent<StreamEntity>()
.RoutingField(r => r.Required(true))
)
);
,但它無法
Invalid NEST response built from a unsuccessful low level call on PUT: /elastic/resources
# Audit trail of this API call:
- [1] BadResponse: Node: https://local.earthml.com:8500/elastic/ Took: 00:00:00.6271828
# ServerError: ServerError: 400Type: illegal_argument_exception Reason: "Mapper for [id] conflicts with existing mapping in other types:
[mapper [id] has different [similarity], mapper [id] is used by multiple types. Set update_all_types to true to update [null_value] across all types.]"
# OriginalException: System.Net.WebException: The remote server returned an error: (400) Bad Request.
at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Elasticsearch.Net.HttpConnection.<RequestAsync>d__14`1.MoveNext()
# Request:
<Request stream not captured or already read to completion by serializer. Set DisableDirectStreaming() on ConnectionSettings to force it to be set on the response.>
# Response:
<Response stream not captured or already read to completion by serializer. Set DisableDirectStreaming() on ConnectionSettings to force it to be set on the response.>
,這裏是我的基類。
public abstract class ResourceEntity
{
public string Id { get; set; }
public string Location { get; set; }
public string Type { get; set; }
}
public class NamedResourceEntity : ResourceEntity
{
public string Name { get; set; }
}
public class StreamEntity : NamedResourceEntity
{
}
public class StreamMessageEntity : ResourceEntity
{
}
截至目前有沒有對他們的許多額外的屬性,但他們會來。我是否需要註冊所有內容或者是否可以在彈性搜索中簡單地使用索引註冊基類。
我希望所有類型都在同一個索引中,並且Type屬性是不同類的分隔符(它對於每個類都是唯一的,並在創建時設置)。