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

ElasticSearch v. 8 upgrade #962

Merged
merged 9 commits into from
Aug 30, 2024
Merged

ElasticSearch v. 8 upgrade #962

merged 9 commits into from
Aug 30, 2024

Conversation

ql
Copy link
Contributor

@ql ql commented Aug 16, 2024

Things to consider:

@ql ql marked this pull request as draft August 16, 2024 17:57
@ql ql changed the base branch from es-8-0-upgrade-poc to master August 16, 2024 17:59
@ql ql changed the title Es 8 0 upgrade poc ElasticSearch v. 8 upgrade Aug 16, 2024
@ql ql mentioned this pull request Aug 16, 2024
7 tasks
- "ES_JAVA_OPTS=-Xms${TEST_ES_HEAP_SIZE:-500m} -Xmx${TEST_ES_HEAP_SIZE:-500m}"
- discovery.type=single-node
- xpack.security.enabled=false
- action.destructive_requires_name=false
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest leaving this default

@konalegi konalegi marked this pull request as ready for review August 19, 2024 08:44
@konalegi konalegi requested a review from a team as a code owner August 19, 2024 08:44
@konalegi konalegi marked this pull request as draft August 19, 2024 08:44
@ql ql force-pushed the es-8-0-upgrade-poc branch from 2a3ca82 to 419e53b Compare August 19, 2024 10:41
@ql ql force-pushed the es-8-0-upgrade-poc branch from 5f2dae7 to d2129a8 Compare August 19, 2024 12:37
@ql ql marked this pull request as ready for review August 19, 2024 12:38
konalegi
konalegi previously approved these changes Aug 21, 2024
Copy link

@konalegi konalegi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice works, the things that I miss

  • let's support both ES 7.x and 8.x, it will be easier to use it in our projects
  • provide a documentation

If you want to keep working on it, but still deliver stuff in smaller pieces, we can create a feature branch and merge your changes there.

'type' => 'mapper_parsing_exception',
'reason' => 'object mapping for [name] tried to parse field [name] as object, but found a concrete value'
'type' => 'document_parsing_exception',
'reason' => '[1:9] object mapping for [name] tried to parse field [name] as object, but found a concrete value'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we try to map with regex? Or what exactly this number [1:9] mean?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's token location, not likely to change IMO.

https://github.com/elastic/elasticsearch/blob/9db177887820c2a210aea1c041a88c162754f034/server/src/main/java/org/elasticsearch/index/mapper/DocumentParser.java#L336

    private static void throwOnConcreteValue(ObjectMapper mapper, String currentFieldName, DocumentParserContext context) {
        throw new DocumentParsingException(
            context.parser().getTokenLocation(),
            "object mapping for ["
                + mapper.fullPath()
                + "] tried to parse field ["
                + currentFieldName
                + "] as object, but found a concrete value"
        );
    }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, let's see how it goes

@@ -32,7 +32,7 @@ def exists?
#
def create(*args, **kwargs)
create!(*args, **kwargs)
rescue Elasticsearch::Transport::Transport::Errors::BadRequest
rescue Elastic::Transport::Transport::Errors::BadRequest

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that we have very small difference between 7.x and 8.x, can we make it work with both version? For instance as a possibility, define these constants like

if es_8?
  ELASTIC_ERROR_NOT_BAD_REQUEST = Elastic::Transport::Transport::Errors::BadRequest end
else 
  ELASTIC_ERROR_NOT_BAD_REQUEST = Elasticsearch::Transport::Transport::Errors::BadRequest 
end

and use it

 def create(*args, **kwargs)
          create!(*args, **kwargs)
        rescue ELASTIC_ERROR_NOT_BAD_REQUEST

Or even make this prefix configurable

if es_8?
  ELASTIC_LIB_CONST_PREFIX = Elastic
else 
  ELASTIC_LIB_CONST_PREFIX = Elasticsearch
end

and then ELASTIC_LIB_CONST_PREFIX::Transport::Transport::Errors::BadRequest, not sure if it's going to work :D

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, it's not likely that we need it: #962 (comment)

@konalegi konalegi dismissed their stale review August 21, 2024 06:44

Wrong button :D

@ql
Copy link
Contributor Author

ql commented Aug 22, 2024

@konalegi it looks like we need to use elasticsearch-transport up to 7.17 to have compatibility mode:

here we have ELASTIC_CLIENT_APIVERSIONING flag:
https://github.com/elastic/elasticsearch-ruby/blob/7.17/elasticsearch-transport/lib/elasticsearch/transport/client.rb#L151

here we don't:
https://github.com/elastic/elastic-transport-ruby/blob/main/lib/elastic/transport/client.rb --

And official migration guide also recommends to start with 7.17 in compatibility mode, fix critical issues and then update libs to 8:
https://www.elastic.co/guide/en/elasticsearch/reference/current/rest-api-compatibility.html

@ql ql requested a review from konalegi August 29, 2024 07:52
CHANGELOG.md Outdated Show resolved Hide resolved
@ql ql force-pushed the es-8-0-upgrade-poc branch from 545118f to e413213 Compare August 30, 2024 08:17
with:
stack-version: 7.10.1
port: 9250
- name: Start containers
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use services for that? The same way we start redis.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@barthez the containers created this way is quite hard to configure (yeah, we have custom configs :D ) , given that the same containers needed for local development as well 🤷 so I find it quite convenient use docker compose based ES.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, sorry, it's possible, I don't remember why we didn't use them from the start.

@ql ql force-pushed the es-8-0-upgrade-poc branch from e413213 to 169fdb9 Compare August 30, 2024 08:21
@konalegi konalegi merged commit 84c0eed into toptal:master Aug 30, 2024
10 checks passed
@amol21p
Copy link

amol21p commented Sep 4, 2024

@konalegi it looks like we need to use elasticsearch-transport up to 7.17 to have compatibility mode:

here we have ELASTIC_CLIENT_APIVERSIONING flag: https://github.com/elastic/elasticsearch-ruby/blob/7.17/elasticsearch-transport/lib/elasticsearch/transport/client.rb#L151

here we don't: https://github.com/elastic/elastic-transport-ruby/blob/main/lib/elastic/transport/client.rb --

And official migration guide also recommends to start with 7.17 in compatibility mode, fix critical issues and then update libs to 8: https://www.elastic.co/guide/en/elasticsearch/reference/current/rest-api-compatibility.html
Can one of you confirm if post this PR, this code would support both ES 7.17 and ES 8 ? Asking since I was looking into making changes for supporting ES 8 in our forked version. And it would make the migration seamless, if we can have the compatible mode

@ql
Copy link
Contributor Author

ql commented Sep 5, 2024

@amol21p this code is not supposed to support ES 7.17 as per official upgrade guide. Compatibility mode is in the ES server, not in libs, so that 7.* libs can work with 8.* server, not the other way around.

So theoretically upgrade goes like this:

  1. Upgrade Elasticsearch server to last 7.17 version
  2. Set ELASTIC_CLIENT_APIVERSIONING=1 env flag and use Chewy 7
  3. Resolve issues (guide is a bit unclear on this, I guess there are deprecation warning in Elastic logs or something like this)
  4. Upgrade Elasticsearch server to 8.15.0
  5. Resolve all deprecation logs warnings "compatible_api"
  6. Upgrade to Chewy 8

I guess for smooth upgrade we need to make sure Chewy 7 plays nice with ES 8 with the flag ELASTIC_CLIENT_APIVERSIONING set

@amol21p
Copy link

amol21p commented Sep 5, 2024

However we had already some changes in our forked version. What would you suggest in that case ?
It would be good to move to a chewy version once with backward compatibility. Otherwise, effort would increase in the migration as we would have to resolve issues twice on ES8 once on the older chewy version and once on the newer version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants