Hi,
I had an issue using new .NET client v8. I used to use v7 client (NEST) but recently decided to migrate to v8 client. let me explain my issue in details.
I have an index with this mappings:
{
"mappings": {
"properties": {
"body": {
"type": "text",
"fields": {
"shingle": {
"type": "text",
"analyzer": "shingle"
}
},
"analyzer": "custom_analyzer"
},
"content_type": {
"type": "keyword"
},
"creation_date": {
"type": "date"
},
"depth": {
"type": "float"
},
"domain": {
"type": "keyword"
},
"h1": {
"type": "text",
"fields": {
"as_you_type": {
"type": "search_as_you_type",
"doc_values": false,
"max_shingle_size": 3
},
"shingle": {
"type": "text",
"analyzer": "shingle"
}
},
"analyzer": "custom_analyzer"
},
"h2": {
"type": "text",
"fields": {
"shingle": {
"type": "text",
"analyzer": "shingle"
}
},
"analyzer": "custom_analyzer"
},
"h3": {
"type": "text",
"fields": {
"shingle": {
"type": "text",
"analyzer": "shingle"
}
},
"analyzer": "custom_analyzer"
},
"h4": {
"type": "text",
"fields": {
"shingle": {
"type": "text",
"analyzer": "shingle"
}
},
"analyzer": "custom_analyzer"
},
"h5": {
"type": "text",
"fields": {
"shingle": {
"type": "text",
"analyzer": "shingle"
}
},
"analyzer": "custom_analyzer"
},
"h6": {
"type": "text",
"fields": {
"shingle": {
"type": "text",
"analyzer": "shingle"
}
},
"analyzer": "custom_analyzer"
},
"http_status": {
"type": "float"
},
"id": {
"type": "keyword"
},
"last_update": {
"type": "date"
},
"meta_description": {
"type": "text",
"analyzer": "custom_analyzer"
},
"meta_keywords": {
"type": "text",
"analyzer": "custom_analyzer"
},
"page_type": {
"type": "keyword"
},
"referrer_page": {
"type": "keyword"
},
"title": {
"type": "text",
"fields": {
"shingle": {
"type": "text",
"analyzer": "shingle"
}
},
"analyzer": "custom_analyzer"
},
"unique_id": {
"type": "keyword"
},
"url": {
"type": "keyword"
}
}
}
}
and related Entity in C# just like this:
public class SearchWebpageDetailsDto
{
[JsonPropertyName("id")]
public string Id { get; set; } = string.Empty;
[JsonPropertyName("unique_id")]
public Guid UniqueId { get; set; }
[JsonPropertyName("domain")]
public string Domain { get; set; } = string.Empty;
[JsonPropertyName("url")]
public string Url { get; set; } = string.Empty;
[JsonPropertyName("title")]
public string Title { get; set; }
[JsonPropertyName("body")]
public string Body { get; set; }
[JsonPropertyName("meta_keywords")]
public List<string> MetaKeywords { get; set; } = [];
[JsonPropertyName("meta_description")]
public List<string> MetaDescription { get; set; } = [];
[JsonPropertyName("h1")]
public List<string> H1 { get; set; } = [];
[JsonPropertyName("h2")]
public List<string> H2 { get; set; } = [];
[JsonPropertyName("h3")]
public List<string> H3 { get; set; } = [];
[JsonPropertyName("h4")]
public List<string> H4 { get; set; } = [];
[JsonPropertyName("h5")]
public List<string> H5 { get; set; } = [];
[JsonPropertyName("h6")]
public List<string> H6 { get; set; } = [];
[JsonPropertyName("last_update")]
public required DateTime LastUpdate { get; set; }
[JsonPropertyName("creation_date")]
public required DateTime CreationDate { get; set; }
[JsonPropertyName("referrer_page")]
public string Referrer { get; set; }
[JsonPropertyName("http_status")]
public int HttpStatus { get; set; }
[JsonPropertyName("depth")]
public long Depth { get; set; }
[JsonPropertyName("content_type")]
public string ContentType { get; set; }
[JsonPropertyName("page_type")]
public int PageType { get; set; }
}
I tried to use a suggest query just like this using v8 client:
var suggestResponse = await _client.SearchAsync<SearchWebpageDetailsDto>(s => s
.Suggest(su => su
.Suggesters(sus => sus
.Add("simple_phrase", sug => sug
.Phrase(ph => ph
.Text(searchPhrase) // searchPhrase is method input param
.Field(f => f.Title.Suffix("shingle"))
.Size(5)
.Confidence(1)
.DirectGenerator(dg => dg
.Field(f => f.Title.Suffix("shingle"))
.PrefixLength(0)
)
.MaxErrors(2)
.Collate(co => co
.Query(q => q
.Source("{\"match\": {\"title\": {\"query\": \"{{suggestion}}\", \"fuzziness\": \"1\", \"operator\": \"and\"}}}")
)
.Prune(false)
)
)
)
)
)
);
But I get an Exception with this message:
Message: Request failed to execute. Call: Status code 400 from: POST /_search?pretty=true&error_trace=true&typed_keys=true. ServerError: Type: parsing_exception Reason: "suggester[phrase] doesn't support field [text]"
I had the same suggest query in v7 NEST with no exceptions or errors and it was just working properly.
My NEST query was this:
var suggestResponse = await _client.SearchAsync<SearchWebpageDetailsDto>(s => s
.Suggest(su => su
.Phrase("simple_phrase", ph => ph
.Text(searchPhrase)
.Field(f => f.Title.Suffix("shingle"))
.Size(5)
.Confidence(1)
.DirectGenerator(dg => dg
.Field(f => f.Title.Suffix("shingle"))
.PrefixLength(0)
)
.MaxErrors(2)
.Collate(co => co
.Query(q => q
.Source("{\"match\": {\"title\": {\"query\": \"{{suggestion}}\", \"fuzziness\": \"1\", \"operator\": \"and\"}}}")
)
.Prune(false)
)
)
)
);
Should mention that I was using NEST property attributes on SearchWebpageDetailsDto
properties for example
[Text(name = "title")]
public string Title { get; set; }
... other properties
But in the new client didn't found same attributes so had to delete them.
How can I solve this problem?
Thanks in Advance.