diff --git a/bids/layout/index.py b/bids/layout/index.py
index 94fd675b..7dd92018 100644
--- a/bids/layout/index.py
+++ b/bids/layout/index.py
@@ -164,10 +164,32 @@ class BIDSLayoutIndexer(object):
         """Index all files in the BIDS dataset. """
         self._index_dir(self.root, self.config)
 
-    def index_metadata(self):
-        """Index metadata for all files in the BIDS dataset. """
+    def index_metadata(self, **filters):
+        """Index metadata for all files in the BIDS dataset.
+
+        Parameters
+        ----------
+
+        **filters
+            keyword arguments passed to the .get() method of a
+            :obj:`bids.layout.BIDSLayout` object.
+            These keyword arguments define what files get selected
+            for metadata indexing.
+        """
+        
+        if filters:
+            # ensure we are returning objects
+            filters['return_type'] = 'object'
+            # until 0.11.0, user can specify extension or extensions
+            ext_key = 'extensions' if 'extensions' in filters else 'extension'
+            if filters.get(ext_key):
+                filters[ext_key] = listify(filters[ext_key])
+                # ensure json files are being indexed
+                if 'json' not in filters[ext_key]:
+                    filters[ext_key].append('json')
+
         # Process JSON files first if we're indexing metadata
-        all_files = self.layout.get(absolute_paths=True)
+        all_files = self.layout.get(absolute_paths=True, **filters)
 
         # Track ALL entities we've seen in file names or metadatas
         all_entities = {}

partial metadata indexing?
I'm curious if anyone has thoughts on partial metadata indexing if metadata indexing takes so long (I do not know if partial metadata indexing would even be helpful, depending on what's taking up the most time).

I patched [BIDSLayoutIndexer's index_metadata function](https://github.com/jdkent/NiBetaSeries/blob/e92f952cdd6136fb85dc0707f6b683efb9cd674c/src/nibetaseries/workflows/utils.py#L19) to allow filters on the get data query.

## Use Case
I'm indexing a large(ish) dataset and only use the metadata associated with the bold files, so I only want to index the metadata for the bold files.

## Question
Would it beneficial (i.e., quicker indexing) to have the option to index metadata for a specific subset of files for a tool that only cares about that subset of files?
diff --git a/bids/layout/tests/test_layout.py b/bids/layout/tests/test_layout.py
index 7c3a55a3..9275e292 100644
--- a/bids/layout/tests/test_layout.py
+++ b/bids/layout/tests/test_layout.py
@@ -12,6 +12,7 @@ import pytest
 import bids
 from bids.layout import (BIDSLayout, parse_file_entities, add_config_paths,
                          Query)
+from bids.layout.index import BIDSLayoutIndexer
 from bids.layout.models import Entity, Config
 from bids.tests import get_test_data_path
 from bids.utils import natural_sort
@@ -21,6 +22,28 @@ def test_layout_init(layout_7t_trt):
     assert isinstance(layout_7t_trt.files, dict)
 
 
+@pytest.mark.parametrize(
+    'index_metadata,query,result',
+    [
+        (True, None, 3.0),
+        (False, None, None),
+        (False, {}, 3.0),
+        (False, {'task': 'rest'}, 3.0),
+        (False, {'task': 'rest', 'extension': ['nii.gz']}, 3.0),
+        (False, {'task': 'rest', 'extension': 'nii.gz'}, 3.0),
+        (False, {'task': 'rest', 'extension': ['nii.gz', 'json'], 'return_type': 'file'}, 3.0),
+    ])
+def test_index_metadata(index_metadata, query, result):
+    data_dir = join(get_test_data_path(), '7t_trt')
+    layout = BIDSLayout(data_dir, index_metadata=index_metadata)
+    if not index_metadata and query is not None:
+        indexer = BIDSLayoutIndexer(layout)
+        indexer.index_metadata(**query)
+    sample_file = layout.get(task='rest', extension='nii.gz', acq='fullbrain')[0]
+    metadata = sample_file.get_metadata()
+    assert metadata.get('RepetitionTime') == result
+
+
 def test_layout_repr(layout_7t_trt):
     assert "Subjects: 10 | Sessions: 20 | Runs: 20" in str(layout_7t_trt)
 

pip install -e .[dev]
parse_log_pytest
pytest
pytest pytest-xdist
3.6
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
alabaster==0.7.13
attrs @ file:///opt/conda/conda-bld/attrs_1642510447205/work
Babel==2.11.0
bids-validator==1.14.0
certifi==2021.5.30
charset-normalizer==2.0.12
docopt==0.6.2
docutils==0.18.1
execnet==1.9.0
greenlet==2.0.2
idna==3.10
imagesize==1.4.1
importlib-metadata @ file:///tmp/build/80754af9/importlib-metadata_1631916693255/work
iniconfig @ file:///home/linux1/recipes/ci/iniconfig_1610983019677/work
Jinja2==3.0.3
m2r==0.3.1
MarkupSafe==2.0.1
mistune==0.8.4
mock==5.2.0
more-itertools @ file:///tmp/build/80754af9/more-itertools_1637733554872/work
nibabel==3.2.2
num2words==0.5.14
numpy==1.19.5
numpydoc==1.1.0
packaging @ file:///tmp/build/80754af9/packaging_1637314298585/work
pandas==1.1.5
patsy==1.0.1
pluggy @ file:///tmp/build/80754af9/pluggy_1615976315926/work
py @ file:///opt/conda/conda-bld/py_1644396412707/work
-e git+https://github.com/bids-standard/pybids.git@35e1296202959d375e570d08078282c26ad02bc0#egg=pybids
Pygments==2.14.0
pyparsing @ file:///tmp/build/80754af9/pyparsing_1635766073266/work
pytest==6.2.4
pytest-xdist==3.0.2
python-dateutil==2.9.0.post0
pytz==2025.2
requests==2.27.1
scipy==1.5.4
six==1.17.0
snowballstemmer==2.2.0
Sphinx==5.3.0
sphinx-rtd-theme==2.0.0
sphinxcontrib-applehelp==1.0.2
sphinxcontrib-devhelp==1.0.2
sphinxcontrib-htmlhelp==2.0.0
sphinxcontrib-jquery==4.1
sphinxcontrib-jsmath==1.0.1
sphinxcontrib-qthelp==1.0.3
sphinxcontrib-serializinghtml==1.1.5
SQLAlchemy==1.4.54
toml @ file:///tmp/build/80754af9/toml_1616166611790/work
typing_extensions @ file:///opt/conda/conda-bld/typing_extensions_1647553014482/work
urllib3==1.26.20
zipp @ file:///tmp/build/80754af9/zipp_1633618647012/work

name: pybids
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - attrs=21.4.0=pyhd3eb1b0_0
  - ca-certificates=2025.2.25=h06a4308_0
  - certifi=2021.5.30=py36h06a4308_0
  - importlib-metadata=4.8.1=py36h06a4308_0
  - importlib_metadata=4.8.1=hd3eb1b0_0
  - iniconfig=1.1.1=pyhd3eb1b0_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.3=he6710b0_2
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - more-itertools=8.12.0=pyhd3eb1b0_0
  - ncurses=6.4=h6a678d5_0
  - openssl=1.1.1w=h7f8727e_0
  - packaging=21.3=pyhd3eb1b0_0
  - pip=21.2.2=py36h06a4308_0
  - pluggy=0.13.1=py36h06a4308_0
  - py=1.11.0=pyhd3eb1b0_0
  - pyparsing=3.0.4=pyhd3eb1b0_0
  - pytest=6.2.4=py36h06a4308_2
  - python=3.6.13=h12debd9_1
  - readline=8.2=h5eee18b_0
  - setuptools=58.0.4=py36h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - toml=0.10.2=pyhd3eb1b0_0
  - typing_extensions=4.1.1=pyh06a4308_0
  - wheel=0.37.1=pyhd3eb1b0_0
  - xz=5.6.4=h5eee18b_1
  - zipp=3.6.0=pyhd3eb1b0_0
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - alabaster==0.7.13
      - babel==2.11.0
      - bids-validator==1.14.0
      - charset-normalizer==2.0.12
      - docopt==0.6.2
      - docutils==0.18.1
      - execnet==1.9.0
      - greenlet==2.0.2
      - idna==3.10
      - imagesize==1.4.1
      - jinja2==3.0.3
      - m2r==0.3.1
      - markupsafe==2.0.1
      - mistune==0.8.4
      - mock==5.2.0
      - nibabel==3.2.2
      - num2words==0.5.14
      - numpy==1.19.5
      - numpydoc==1.1.0
      - pandas==1.1.5
      - patsy==1.0.1
      - pygments==2.14.0
      - pytest-xdist==3.0.2
      - python-dateutil==2.9.0.post0
      - pytz==2025.2
      - requests==2.27.1
      - scipy==1.5.4
      - six==1.17.0
      - snowballstemmer==2.2.0
      - sphinx==5.3.0
      - sphinx-rtd-theme==2.0.0
      - sphinxcontrib-applehelp==1.0.2
      - sphinxcontrib-devhelp==1.0.2
      - sphinxcontrib-htmlhelp==2.0.0
      - sphinxcontrib-jquery==4.1
      - sphinxcontrib-jsmath==1.0.1
      - sphinxcontrib-qthelp==1.0.3
      - sphinxcontrib-serializinghtml==1.1.5
      - sqlalchemy==1.4.54
      - urllib3==1.26.20
prefix: /opt/conda/envs/pybids

bids/layout/tests/test_layout.py::test_index_metadata[False-query3-3.0] bids/layout/tests/test_layout.py::test_index_metadata[False-query4-3.0] bids/layout/tests/test_layout.py::test_index_metadata[False-query5-3.0] bids/layout/tests/test_layout.py::test_index_metadata[False-query6-3.0]
bids/layout/tests/test_layout.py::test_layout_init bids/layout/tests/test_layout.py::test_index_metadata[True-None-3.0] bids/layout/tests/test_layout.py::test_index_metadata[False-None-None] bids/layout/tests/test_layout.py::test_index_metadata[False-query2-3.0] bids/layout/tests/test_layout.py::test_layout_repr bids/layout/tests/test_layout.py::test_load_description bids/layout/tests/test_layout.py::test_get_file bids/layout/tests/test_layout.py::test_get_metadata bids/layout/tests/test_layout.py::test_get_metadata2 bids/layout/tests/test_layout.py::test_get_metadata3 bids/layout/tests/test_layout.py::test_get_metadata4 bids/layout/tests/test_layout.py::test_get_metadata_meg bids/layout/tests/test_layout.py::test_get_metadata5 bids/layout/tests/test_layout.py::test_get_metadata_via_bidsfile bids/layout/tests/test_layout.py::test_get_with_bad_target bids/layout/tests/test_layout.py::test_get_bvals_bvecs bids/layout/tests/test_layout.py::test_get_subjects bids/layout/tests/test_layout.py::test_get_fieldmap bids/layout/tests/test_layout.py::test_get_fieldmap2 bids/layout/tests/test_layout.py::test_bids_json bids/layout/tests/test_layout.py::test_get_return_type_dir bids/layout/tests/test_layout.py::test_get_val_none[None] bids/layout/tests/test_layout.py::test_get_val_none[Query.NONE] bids/layout/tests/test_layout.py::test_get_val_enum_any bids/layout/tests/test_layout.py::test_get_return_sorted bids/layout/tests/test_layout.py::test_ignore_files bids/layout/tests/test_layout.py::test_force_index bids/layout/tests/test_layout.py::test_nested_include_exclude bids/layout/tests/test_layout.py::test_nested_include_exclude_with_regex bids/layout/tests/test_layout.py::test_layout_with_derivs bids/layout/tests/test_layout.py::test_layout_with_multi_derivs[None] bids/layout/tests/test_layout.py::test_get_layouts_in_scope[None] bids/layout/tests/test_layout.py::test_get_dataset_description[None] bids/layout/tests/test_layout.py::test_layout_with_multi_derivs[bidsdb0] bids/layout/tests/test_layout.py::test_get_layouts_in_scope[bidsdb0] bids/layout/tests/test_layout.py::test_get_dataset_description[bidsdb0] bids/layout/tests/test_layout.py::test_layout_with_multi_derivs[bidsdb1] bids/layout/tests/test_layout.py::test_get_layouts_in_scope[bidsdb1] bids/layout/tests/test_layout.py::test_get_dataset_description[bidsdb1] bids/layout/tests/test_layout.py::test_query_derivatives bids/layout/tests/test_layout.py::test_restricted_words_in_path bids/layout/tests/test_layout.py::test_derivative_getters bids/layout/tests/test_layout.py::test_get_tr bids/layout/tests/test_layout.py::test_to_df bids/layout/tests/test_layout.py::test_parse_file_entities bids/layout/tests/test_layout.py::test_parse_file_entities_from_layout[None] bids/layout/tests/test_layout.py::test_parse_file_entities_from_layout[bidsdb-synth0] bids/layout/tests/test_layout.py::test_parse_file_entities_from_layout[bidsdb-synth1] bids/layout/tests/test_layout.py::test_deriv_indexing bids/layout/tests/test_layout.py::test_add_config_paths bids/layout/tests/test_layout.py::test_layout_in_scope bids/layout/tests/test_layout.py::test_indexed_file_associations bids/layout/tests/test_layout.py::test_layout_save bids/layout/tests/test_layout.py::test_indexing_tag_conflict bids/layout/tests/test_layout.py::test_get_with_wrong_dtypes bids/layout/tests/test_layout.py::test_get_with_regex_search bids/layout/tests/test_layout.py::test_get_with_regex_search_bad_dtype bids/layout/tests/test_layout.py::test_load_layout
bids/layout/index.py
bids/layout/index.py