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

Mappings update trigger a reindex #2333

Closed
wants to merge 8 commits into from
Closed

Conversation

clementbolin
Copy link
Contributor

@clementbolin clementbolin commented Apr 16, 2022

What does this PR do ?

reindex documents with the new mappings (collection:update)

How should this be manually tested?

Add a few documents in it.
Then add mappings to describe the fields in the added documents.

Expected: running a document:search in the collection should return the searched documents.

or run the functional tests

@clementbolin clementbolin marked this pull request as draft April 16, 2022 10:46
@clementbolin clementbolin self-assigned this Apr 16, 2022
@codecov
Copy link

codecov bot commented Apr 16, 2022

Codecov Report

Merging #2333 (a95aa4c) into 2-dev (bdc3ba3) will decrease coverage by 0.00%.
The diff coverage is 75.00%.

@@            Coverage Diff             @@
##            2-dev    #2333      +/-   ##
==========================================
- Coverage   91.44%   91.43%   -0.01%     
==========================================
  Files         118      118              
  Lines        8033     8037       +4     
==========================================
+ Hits         7346     7349       +3     
- Misses        687      688       +1     
Impacted Files Coverage Δ
lib/service/storage/elasticsearch.js 92.76% <75.00%> (-0.09%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bdc3ba3...a95aa4c. Read the comment docs.

@clementbolin clementbolin linked an issue Apr 16, 2022 that may be closed by this pull request
@clementbolin clementbolin added changelog:new-features Increase the minor version number 2.x labels Apr 16, 2022
@clementbolin clementbolin changed the title Mappings update should trigger a reindex Mappings update trigger a reindex Apr 16, 2022
@clementbolin clementbolin marked this pull request as ready for review April 16, 2022 16:27
@sonarcloud
Copy link

sonarcloud bot commented Apr 16, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@@ -38,6 +38,29 @@ Feature: Collection Controller
Then I should receive a "hits" array of objects matching:
| _id | _source |
| "document-1" | { "age": 2 } |

Scenario: Update a collection and search document (dyanmic false)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Scenario: Update a collection and search document (dyanmic false)
Scenario: Update a collection and search document (dynamic false)

@@ -1387,6 +1387,20 @@ class ElasticSearch extends Service {

await this.updateMapping(index, collection, mappings);

// update documents with new mappings
if (previousMappings.dynamic === 'false' && (await this._client.search(esRequest)).body.hits.hits.length > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

If think it's better to call count than search if you just want to know if there are documents to update

Side note:
Avoid putting long calls with chained property access like this in condition for clarity await this._client.search(esRequest)).body.hits.hits.length prefer storing the result in a const variable.
Conditions that are too long and uses && or || should be splitted on multiple lines like so

const documentsCount = await this._client.search(esRequest)).body.hits.hits.length;
if ( previousMappings.dynamic === 'false'
  && documentsCount > 0
) {

Comment on lines +50 to +59
When I "update" the collection "nyc-open-data":"green-taxi" with:
| mappings | { "properties": { "age": { "type": "long" } } } |
When I search documents with the following query:
"""
{
"match": {
"age": 2
}
}
"""
Copy link
Contributor

Choose a reason for hiding this comment

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

It's good but you also need to verify that the search does not match the field age before updating the mapping and triggering the reindex

@clementbolin clementbolin marked this pull request as draft May 2, 2022 19:13
@Aschen
Copy link
Contributor

Aschen commented Jan 2, 2023

Closed due to inactivity

@Aschen Aschen closed this Jan 2, 2023
@rolljee rolljee deleted the feat/trigger-reindex branch December 6, 2023 10:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.x changelog:new-features Increase the minor version number
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mappings update should trigger a reindex
3 participants