Skip to content
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

Cannot use RawJsonQuery #8195

Open
gpetrou opened this issue May 23, 2024 · 6 comments
Open

Cannot use RawJsonQuery #8195

gpetrou opened this issue May 23, 2024 · 6 comments
Labels
8.x Relates to 8.x client version Category: Bug

Comments

@gpetrou
Copy link
Contributor

gpetrou commented May 23, 2024

Elastic.Clients.Elasticsearch version: 8.13.10

Elasticsearch version: 8.13.2

.NET runtime version: 8.0

Operating system version:

Description of the problem including expected versus actual behavior:
Try to execute the following code:

Elastic.Clients.Elasticsearch.QueryDsl.RawJsonQuery rawQuery = new("{\"term\": { \"fieldname\": \"value\"  }}");

SearchRequest<JsonObject> elasticSearchRequest = new("IndexName")
{
    Query = rawQuery
};

Elastic.Clients.Elasticsearch.SearchResponse<JsonObject> expected = await _elasticsearchClient.SearchAsync<JsonObject>(elasticSearchRequest);

It results in:

{
  "query": {
    "raw_json": {"term": { "fieldname": "value"  }}
  }
}

Therefore there is a parsing_exception.

Steps to reproduce:
1.
2.
3.

Expected behavior
A clear and concise description of what you expected to happen.

Provide ConnectionSettings (if relevant):

Provide DebugInformation (if relevant):

@gpetrou gpetrou added 8.x Relates to 8.x client version Category: Bug labels May 23, 2024
@gpetrou
Copy link
Contributor Author

gpetrou commented May 23, 2024

@flobernd looks like the issue is in one of your generated files, so I cannot just change that. Can you please fix it? I assume that for raw json, we shouldn't use writer.WriteStartObject();, writer.WritePropertyName(value.VariantName);, etc...

@flobernd
Copy link
Member

flobernd commented May 27, 2024

Hi @gpetrou,

the RawJsonQuery is a bit of a hack. The most easiest fix for me would be to separate the variant-name (e.g. "term") from the rest of the query payload:

var q = new RawJsonQuery("term", "{ \"fieldname\": \"value\"  }");

Would that work for you?


Special handling in the generator is possible, but I'd like to avoid that.

Btw.: In general you should prefer not using the RawJsonQuery, if the functionality is otherwise supported in the client. This construct was only added as a last-resort fallback when the client was still lacking a lot of features. Is there a specific reason for using RawJsonQuery in your case? I'm curious if I can "properly" improve things to simplify your use-case.

@gpetrou
Copy link
Contributor Author

gpetrou commented May 27, 2024

There are still cases such as #8169 (comment) where this seems to be needed. I would expect this to work similarly to Nest.RawQuery.

@flobernd
Copy link
Member

Yes, this case would work.

@tabareh
Copy link

tabareh commented May 27, 2024

Hi @gpetrou,

the RawJsonQuery is a bit of a hack. The most easiest fix for me would be to separate the variant-name (e.g. "term") from the rest of the query payload:

var q = new RawJsonQuery("term", "{ \"fieldname\": \"value\"  }");

Would that work for you?

Special handling in the generator is possible, but I'd like to avoid that.

Btw.: In general you should prefer not using the RawJsonQuery, if the functionality is otherwise supported in the client. This construct was only added as a last-resort fallback when the client was still lacking a lot of features. Is there a specific reason for using RawJsonQuery in your case? I'm curious if I can "properly" improve things to simplify your use-case.

There is well no RawJsonQuery constructor that accepts two params at least for version 8.13.12 that I use

@flobernd
Copy link
Member

@tabareh Yes, this will be available after I released a fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
8.x Relates to 8.x client version Category: Bug
Projects
None yet
Development

No branches or pull requests

3 participants