-
Notifications
You must be signed in to change notification settings - Fork 1.2k
PutMappingAsync fails with Bad Request when PutMappingRequest.DynamicTemplates contains just one element #7968
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi @yansklyarenko, thanks for the detailed report. In the specification, the dynamic_templates?: Record<string, MappingDynamicTemplate> | Record<string, MappingDynamicTemplate>[] This might be incorrect. I'll try to confirm by looking in the ES server code. |
I've also encountered the same bug. Not fixed in version 8.12. |
I have found a workaround for this issue. When issuing a put mapping request, you can check whether the
|
#7337 addresses the defect related to the |
What is the state of this bug? |
@l-trotta Do you have the same issue with the Java client? |
@flobernd tested the same request with the java client, seems to be working normally: var template = DynamicTemplate.of(d -> d.mapping(m -> m.keyword(k -> k)).pathMatch("test"));
var putMappingRequest = PutMappingRequest.of(p -> p.index("my-index").dynamicTemplates(Map.of("testTemplate",template)));
var response = esClient.indices().putMapping(putMappingRequest); |
We just confirmed that the specification is indeed wrong about this one. This will be fixed in the client after the specification PR is merged and a new version of the client is released. |
Elastic.Clients.Elasticsearch version: 8.10.0
Elasticsearch version: 8.2.2
.NET runtime version: net6.0, net7.0
Operating system version: Windows 10
Description of the problem including expected versus actual behavior:
Consider the following code sample:
Actual behavior
The response is invalid, containing 400 bad request:
Expected behavior
The appropriate mapping is added to the index.
Some details which might be useful
As soon as I add another element to the
DynamicTemplates
array, the request passes just fine and the mapping is created. This is because theDynamicTemplates
property is decorated with[SingleOrManyCollectionConverter(typeof(IDictionary<string, DynamicTemplate>))]
, which serializes the array with a single element as an object, not as an array.Based on this comment from another issue, I make a conclusion that it was done on purpose. So, it is not clear whether it is the 'put mapping' endpoint problem that it doesn't understand the new body format, or the serialization logic.
Please, let me know if you need some more details.
The text was updated successfully, but these errors were encountered: