Я новичок в мире elasticsearch, и у меня есть требование искать документы с определенными c GUID. Я уже понял, что для этого мне нужно сопоставить поле GUID как поле ключевого слова. В производстве уже есть код, который выполняет индексацию документов, но сопоставление не выполняется. См. Ниже фактический код:
public class ProjectFileES
{
public Guid ClientId { get; set; }
public Guid ProjectId { get; set; }
public string DisplayName { get; set; }
public string FileName { get; set; }
public string Content { get; set; }
}
[...]
var _bulkDescriptor = new BulkDescriptor();
_bulkDescriptor.CreateMany<ProjectFileES>(list, (bd, q) =>
bd.Id(q.Id.ToString())
.Index($"{AppConstants.ES_IndexName}-{DateTime.UtcNow.ToString("yyyy-MM-dd")}")
.Type(AppConstants.ES_Type)
);
return await Client.BulkAsync(_bulkDescriptor);
Как я читал в документации Elasti c, идентификаторы GUID автоматически сопоставляются с типом ключевого слова, как вы можете видеть ниже.
{
"mappings": {
"projectfilees": {
"properties": {
"clientId": {
"type": "keyword"
},
"projectId": {
"type": "keyword"
},
"displayName": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"fileName": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"content": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"id": {
"type": "keyword"
}
}
}
}
}
# Response:
{
"acknowledged" : true,
"shards_acknowledged" : true,
"index" : "roger-test3"
}
Но теперь я пытаюсь выполнить поиск, передав идентификатор проекта документа, который проиндексирован, как показано ниже:
var response = await _elastic.SearchAsync<ProjectFileES>(s => s.RequestConfiguration(c => c.DisableDirectStreaming())
.Index("*")
.Query(q =>
q.Bool(b => b
.Filter(f => f
.Term(t => t.ProjectId, projectId)
)
)
)
);
, но мой объект ответа не имеет возвращенных документов: Объект ответа
Вот ответ JSON внутри свойства DebugInformation:
{
"query": {
"bool": {
"filter": [
{
"term": {
"ProjectId": {
"value": "45efa5d0-8b41-11ea-871b-e3b070662e35"
}
}
}
]
}
}
}
# Response:
{
"took" : 48,
"timed_out" : false,
"_shards" : {
"total" : 373,
"successful" : 373,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : 0,
"max_score" : null,
"hits" : [ ]
}
}
Есть помощь?