Skip to content

Conversation

quux00
Copy link
Contributor

@quux00 quux00 commented Aug 1, 2025

The RootObjectNamespaceValidator allows prohibiting "namespaces" or top level fields in
Elasticsearch mappings: both "normal" index mappings and runtime mappings.

The same validator is used to check both index-time runtime mappings and query-time index mappings.

The primary target use case for this SPI is a feature in serverless to prohibit mappings like
_project or _project.my_sub_field, but the mechanism provided in this PR allows any
possible namespace detection and prevention.

@quux00 quux00 force-pushed the cross-project/prohibit-_project-mappings branch 3 times, most recently from 16994be to 1ddcf5a Compare August 20, 2025 17:03
@quux00 quux00 force-pushed the cross-project/prohibit-_project-mappings branch from 1ddcf5a to 64eddb6 Compare August 26, 2025 13:37
quux00 added 11 commits August 26, 2025 13:53
1. One case with subobjects:false doesn't work as hoped:

// this does NOT return an error - it just silently "fails" to create the _project entry
PUT test333?error_trace=true
{
   "mappings": {
     "subobjects": false,
     "properties" : {
      "_project" : {
        "type" : "object"
      }
    }
  }
}

// YAY - this one fails with correct error message
PUT test333?error_trace=true
{
  "mappings": {
    "subobjects": false,
    "properties": {
      "_project": {
        "type": "object",
        "properties": {
          "myfield": {
            "type": "keyword"
          }
        }
      }
    }
  }
}

2. Creating a runtime mapping is not detected and prevented:

PUT /rt-index
{
  "mappings": {
    "runtime": {
      "_project": {
        "type": "keyword",
        "script": {
          "source": "emit(doc['existing_field'].value + ' some additional text')"
        }
      }
    }
  }
}
…ssField can call it without a Mapper reference
This prevents _project or _project.foo mappings in query-time runtime mappings.

For example, these now fail with "Mapping rejected: [_project.foo]. No mappings of [_project] are allowed in order to avoid conflicts with project metadata tags in serverless"
GET /blogs/_search
{
  "runtime_mappings": {
    "_project": {
      "type": "keyword",
      "script": {
        "source": "emit('somevalue')"
      }
    }
  },
  "query": {
    "match_all": {}
  },
  "fields": ["_project"]
}

GET /blogs/_search
{
  "runtime_mappings": {
    "_project.foo": {
      "type": "keyword",
      "script": {
        "source": "emit('somevalue')"
      }
    }
  },
  "query": {
    "match_all": {}
  },
  "fields": ["_project.foo"]
}
…d.parseRuntimeFields.

Removed checks from RootObjectMapper and IndexService.
This checks both query-time and index-time runtime field mappings.
@quux00 quux00 force-pushed the cross-project/prohibit-_project-mappings branch from 64eddb6 to af4964f Compare August 26, 2025 17:53
@quux00 quux00 requested a review from javanna August 26, 2025 18:02
@quux00 quux00 changed the title Prohibit _project mappings in serverless Create SPI to allow prohibiting certain top-level mappings Aug 26, 2025
Copy link
Member

@javanna javanna left a comment

Choose a reason for hiding this comment

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

solid work, I left some minor comments.

@quux00 quux00 added :Search Foundations/Mapping Index mappings, including merging and defining field types Team:Search Foundations Meta label for the Search Foundations team in Elasticsearch >non-issue labels Aug 28, 2025
@quux00 quux00 marked this pull request as ready for review August 28, 2025 20:46
@quux00 quux00 requested a review from a team as a code owner August 28, 2025 20:46
@elasticsearchmachine
Copy link
Collaborator

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

Copy link
Member

@javanna javanna left a comment

Choose a reason for hiding this comment

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

LGTM

@quux00 quux00 merged commit ba60ed7 into elastic:main Sep 19, 2025
34 checks passed
szybia added a commit to szybia/elasticsearch that referenced this pull request Sep 19, 2025
* upstream/main:
  Turn NumericValues into functional interface (elastic#135068)
  Improve block loader for source only runtime fields of type keyword (elastic#135026)
  Mute org.elasticsearch.xpack.esql.qa.single_node.EsqlSpecIT test {csv-spec:stats.StdDeviationGroupedAllTypes} elastic#135103
  Mute org.elasticsearch.xpack.esql.qa.single_node.EsqlSpecIT test {csv-spec:stats.StdDeviationWithLongs} elastic#135102
  Mute org.elasticsearch.xpack.esql.qa.single_node.EsqlSpecIT test {csv-spec:inlinestats.StdDevFilter} elastic#135101
  Mute org.elasticsearch.xpack.esql.qa.single_node.EsqlSpecIT test {csv-spec:stats.StdDevFilter} elastic#135100
  Remove track_live_docs_in_memory_bytes feature flag (elastic#134900)
  Create SPI to allow prohibiting certain top-level mappings (elastic#132360)
  Only validate primary ids on release branches (elastic#135044)
  Added no-op support for project_routing query param to REST endpoints that will support cross-project search (elastic#134741)
  Fix race in FileSettingsServiceIT.testSettingsAppliedOnStart (elastic#134368)
elasticsearchmachine pushed a commit that referenced this pull request Sep 22, 2025
`subobjects:auto` is guarded behind a feature flag, not enabled. #132360
added tests without proper guarding.

Fixes #135134
gmjehovich pushed a commit to gmjehovich/elasticsearch that referenced this pull request Sep 22, 2025
`subobjects:auto` is guarded behind a feature flag, not enabled. elastic#132360
added tests without proper guarding.

Fixes elastic#135134
DonalEvans pushed a commit to DonalEvans/elasticsearch that referenced this pull request Sep 22, 2025
`subobjects:auto` is guarded behind a feature flag, not enabled. elastic#132360
added tests without proper guarding.

Fixes elastic#135134
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

>non-issue :Search Foundations/Mapping Index mappings, including merging and defining field types Team:Search Foundations Meta label for the Search Foundations team in Elasticsearch v9.2.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants