Skip to content

Unify conversion services for value replacement when querying elasticsearch #2833

Closed
@puppylpg

Description

@puppylpg

With the SpEL expression support in @Query introduced in #2826, here comes a new ConversionService with ElasticsearchCollectionValueToStringConverter and ElasticsearchStringValueToStringConverter to convert the query values in elasticsearch query. We don't register these two converters into the default ConversionService on purpose to avoid the misconversion in a common situation(eg, common string to string doesn't need quotation escape).

However, Converters configured by users are registered into the default ConversionService rather than this one, so it doesn't have the ability to convert custom object(for example SampleProperty) when using SpEL:

		@Query("""
				{
				  "bool":{
				    "must":[
				      {
				        "term":{
				          "sample_property": "#{#sampleProperty}"
				        }
				      }
				    ]
				  }
				}
				""")
		SearchHits<SampleEntity> queryBySamplePropertySpEL(SampleProperty sampleProperty);

So we should:

  • propose1: unify the two ConversionService. Let the new ConversionService have all the ability the default ConversionService have, not vise versa;

Another problem is that when using placeholder(?0, ?1...) in @Query, null value will be converted to string "null", and this should be considered a bug as stated in #2826 (comment). The simplest way to deal with that is to use the new ConversionService in StringQueryUtil, since the conversion logic has already been well handled in ConversionService.

  • propose2: replece the old logic for values conversion in StringQueryUtil;

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions