Skip to content

Detect when copying to a non-existent field when dynamic mappings are disabled #112812

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

Open
Mikep86 opened this issue Sep 12, 2024 · 17 comments · May be fixed by #113356, #113290 or #127098
Open

Detect when copying to a non-existent field when dynamic mappings are disabled #112812

Mikep86 opened this issue Sep 12, 2024 · 17 comments · May be fixed by #113356, #113290 or #127098
Labels
>enhancement good first issue low hanging fruit :Search Foundations/Mapping Index mappings, including merging and defining field types :SearchOrg/Relevance Label for the Search (solution/org) Relevance team Team:Search Foundations Meta label for the Search Foundations team in Elasticsearch

Comments

@Mikep86
Copy link
Contributor

Mikep86 commented Sep 12, 2024

Description

We should be able to detect when a user is attempting to use copy_to to copy to a non-existent field when dynamic mappings are disabled. For example:

PUT test-index
{
  "mappings": {
    "dynamic": false,
    "properties": {
      "test_field": {
        "type": "text",
        "copy_to": "missing_field"
      }
    }
  }
}

Currently, this request succeeds even though nothing will ever be copied to missing_field. We should throw a 400 error in this case to indicate to the user that their mappings are invalid.

@Mikep86 Mikep86 added :Search Foundations/Mapping Index mappings, including merging and defining field types >enhancement labels Sep 12, 2024
@elasticsearchmachine elasticsearchmachine added the Team:Search Foundations Meta label for the Search Foundations team in Elasticsearch label Sep 12, 2024
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-search-foundations (Team:Search Foundations)

@kderusso kderusso added the good first issue low hanging fruit label Sep 12, 2024
@Mikep86 Mikep86 added the :SearchOrg/Relevance Label for the Search (solution/org) Relevance team label Sep 12, 2024
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/search-relevance (Team:Search - Relevance)

@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/ent-search-eng (Team:SearchOrg)

@Obolrom
Copy link

Obolrom commented Sep 13, 2024

@Mikep86 could you please assign this issue to me?

@Mikep86
Copy link
Contributor Author

Mikep86 commented Sep 13, 2024

@Obolrom Great to hear you're interested in addressing this issue! Please feel free to submit a PR for this, but we don't officially assign tasks to community members. I highly doubt someone at Elastic will address this before you do though :)

@henriquepaes1
Copy link
Contributor

Hello! @Obolrom let me know if you're still interested in solving this issue. Otherwise, I would like to work on it.

@Obolrom
Copy link

Obolrom commented Sep 20, 2024

@henriquepaes1
I have a lot of work. So yeah, take it)

@henriquepaes1
Copy link
Contributor

Hello @Mikep86! I'm currently working on this issue. I found the "copy-to" verifications in the FieldMapper class in order to insert the non-existent field verification. However, I have a question: what is the expected behavior when dynamic mappings are enabled?

@Mikep86
Copy link
Contributor Author

Mikep86 commented Sep 20, 2024

@henriquepaes1 We expect the request to succeed in that case because the target field can be dynamically created. Note that I expect the solution to involve FieldTypeLookup, as that is where all the mappers can be validated with respect to one another.

@henriquepaes1
Copy link
Contributor

@Mikep86 I appreciate the prompt reply. I understood the expected behavior and what the solution should envolve, I'll work on that later today.

@likithy
Copy link

likithy commented Sep 22, 2024

@henriquepaes1 We expect the request to succeed in that case because the target field can be dynamically created. Note that I expect the solution to involve FieldTypeLookup, as that is where all the mappers can be validated with respect to one another.

@Mikep86 can you please review this and approve i tried to work on enhancement

@ioanatia
Copy link
Contributor

We do want to make sure that we pay attention to index templates.

Example:

PUT _index_template/template_1
{
  "index_patterns": ["test-index*"],
  "template": {
    "mappings": {
      "properties": {
        "missing_field": {
          "type": "text"
        }
      }
    }
  }
}

PUT test-index
{
  "mappings": {
    "dynamic": false,
    "properties": {
      "test_field": {
        "type": "text",
        "copy_to": "missing_field"
      }
    }
  }
}

GET test-index

PUT test-index/_doc/12
{
  "test_field": "hello"
}

# this will return results
GET test-index/_search
{
  "query": {
    "match": {
      "missing_field": "hello"
    }
  }
}

In this case the test-index index uses an index template that specifies a mapping for missing_field so we should not fail the PUT test-index request.

@henriquepaes1
Copy link
Contributor

Hey @ioanatia thanks for pointing this out! I tested my solution with that case and while it worked fine, it raised some questions.

1- What is the difference between using the MappingLookup class and the FieldTypeLookup @Mikep86 mentioned a few comments above?
2- Would you help me writing a test case for the cenario you described? I didn't found any test in the CopyToMapperTests class that uses templates.

@kunal5042
Copy link

Hi Mikep86,

Can I work on this issue, I'm very new in terms on contributing to open-source, as far as I've understood, this is not resolved yet and has been marked with good first issue label. Kindly let me know if it's okay for me to pick this up.

Thanks & Regards

@chandu05-dev
Copy link

Hi Mikep86,

Can I work on this issue, I'm very new in terms on contributing to open-source, as far as I've understood, this is not resolved yet and has been marked with good first issue label. Kindly let me know if it's okay for me to pick this up.

Thanks & Regards

Hey Kunal,
hope you are doing well. I am new to opensource development and wanted to ask how has your journey been so far. I would love to collaborate with you so that I can learn from you.

@priorigratia
Copy link

@henriquepaes1 are you still working on this issue? If not, would love to take this up.

@BinhMike
Copy link

Hi Mikep86,

Can I work on this issue. As I've understood, this is not resolved yet and has been marked with issue label. Kindly let me know if it's okay for me to pick this up.

Thanks & Regards

@BinhMike BinhMike linked a pull request Apr 20, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>enhancement good first issue low hanging fruit :Search Foundations/Mapping Index mappings, including merging and defining field types :SearchOrg/Relevance Label for the Search (solution/org) Relevance team Team:Search Foundations Meta label for the Search Foundations team in Elasticsearch
Projects
None yet