Search problem, contains unrecognized parameter: [typed_keys]

Using Previous versions of NEST this code was working: (c#)

var rangeDateQuery = new DateRangeQuery();
//some rangeDateQuery configurations
var emailQuery = new TermQuery();
//some emailQuery configurations

return await this.Client.SearchAsync<Information>(s => s.Query(q => rangeDateQuery && emailQuery));

Now with NEST 6.0.1 I'm receiving this error:

What version of Elasticsearch are you targeting?

Interestingly, I'm getting the same error, using ES version:

  "version" : {
    "number" : "6.2.2",
    "build_hash" : "10b1edd",
    "build_date" : "2018-02-16T19:01:30.685723Z",
    "build_snapshot" : false,
    "lucene_version" : "7.2.1",
    "minimum_wire_compatibility_version" : "5.6.0",
    "minimum_index_compatibility_version" : "5.0.0"
  },

And using the NEST API in dotnet core via v6.0.1 of the Nuget package.

I seem to get ?typed_keys=true on the end of my queries:

Invalid NEST response built from a unsuccessful low level call on POST: /post/post/_search?typed_keys=true
# Audit trail of this API call:
 - [1] BadResponse: Node: xxx Took: 00:00:00.0683456
# OriginalException: Elasticsearch.Net.ElasticsearchClientException: Request failed to execute. ServerError: Type: illegal_argument_exception Reason: "request [/post/post/_search] contains unrecognized parameter: [typed_keys]"
# Request:
{"from":0,"size":1000,"query":{"bool":{"should":[{"terms":{"title":["a"]}},{"terms":{"content":["a"]}}]}}}
# Response:
{"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"request [/post/post/_search] contains unrecognized parameter: [typed_keys]"}],"type":"illegal_argument_exception","reason":"request [/post/post/_search] contains unrecognized parameter: [typed_keys]"},"status":400}

Even though this is not being specified (and I can't seem to see how to specify it) when creating a query:

            var result = await _elasticService.ExecuteQueryAsync<Post>(s => s.From(from).Size(size).Source(src => src)
                .Sort(sort => sort.Descending(x => x.CreationDate))
                .Index(_elasticService.GetIndexName(typeof(Post))));

Just to add, we have recently upgraded from NEST 5.0 on ES 5.4 to NEST 6.0.1 on ES 6.2.2, which seems to have introduced this, but this has also been a decent amount of refactoring work, so it is possible that we have introduced it there.

Hah, fixed my own problem. Turned out I just couldn't find the method that I needed.

So the default behaviour in older versions was to default the typed_keys value to false. The NEST team have changed the API so that it now takes a Nullable, and this defaults to true.

To fix your code: Append .TypedKeys(null) to the ISearchRequest, eg:

            var result = await _elasticService.ExecuteQueryAsync<Post>(s => s.From(from).Size(size).Source(src => src)
                .Sort(sort => sort.Descending(x => x.CreationDate))
                .Index(_elasticService.GetIndexName(typeof(Post)))
                .TypedKeys(null)
);

This seems to work for me, but I'll caveat it by saying that I don't know what I'm doing and I have no idea of the possible side effects of this.

Thanks for the detailed version information @lawrence.anstey.

Setting TypedKeys(null) on the request will remove the parameter; it's used for suggesters and aggregations by the client to ascertain which .NET type to deserialize each suggester/aggregation response into, without needing to rely on heuristics and the presence of specific JSON properties.

Thanks @forloop - do we know what server version(s) typed_keys is available for? It sounds like it would be better for performance to set it to true. Will this be available in 6.x eventually, or should we just automatically append .TypedKeys(null) to every ISearchRequest?

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.