1、当我使用ES的client.IndexAsync(user,"user")报错了
Invalid Elasticsearch response built from a unsuccessful (405) low level call on PUT: /user/_doc # Audit trail of this API call: - [1] BadResponse: Node: http://127.0.0.1:9200/ Took: 00:00:00.4482830 # OriginalException: Elastic.Transport.TransportException: Request failed to execute. Call: Status code 405 from: PUT /user/_doc. ServerError: Type: Reason: "Incorrect HTTP method for uri [/user/_doc] and method [PUT], allowed: [POST]" # Request: <Request stream not captured or already read to completion by serializer. Set DisableDirectStreaming() on TransportConfiguration to force it to be set on the response.> # Response: {"error":"Incorrect HTTP method for uri [/user/_doc] and method [PUT], allowed: [POST]","status":405}
我百思不得其解,官方文档创建索引的教程,一样的方法却报错了
在我查询该方法的源码才得知,默认为PUT方法。由于我的User类是没有id这个属性的,而ES默认会从实体类中查询到id,作为ES的id。后来改成这种方法就可以了。
附带一下解析源码: