Docs Menu
Docs Home
/
MongoDB Atlas
/ / / /

How to Index Numeric Values

On this page

  • Define the Index for the number Type
  • Configure number Field Properties
  • Try an Example for the number Type

You can use the Atlas Search number type to index fields with numeric values of int32, int64, and double data types. You can use the equals, range, and near operators to query indexed fields of type number.

Note

To query numeric values in arrays, you can use only the range operator.

Atlas Search doesn't automatically index numeric values for faceting. Instead, you must index the numeric values using numberFacet to run a facet query on number fields.

Atlas Search automatically indexes all numeric fields in indexes created after July 2023 for sorting the Atlas Search results. For preexisting indexes, you must rebuild the index to use number fields in the index for sorting. To learn more, see Update Your Existing Index and Sort Atlas Search Results.

If you enable dynamic mappings, Atlas Search automatically indexes fields of type number. You can use the Visual Editor or the JSON Editor in the Atlas UI to index fields as the number type.

The Atlas Search number type has the following parameters:

UI Field Name
JSON Option
Type
Necessity
Description
Default
Data Type
type
string
Required
Human-readable label that identifies this field type. Value must be number.
Representation
representation
string
Optional

Data type of the field to index. Values are:

  • int64 - for indexing large integers without loss of precision and for rounding double values to integers. You can't use this type to index large double values.

  • double - for indexing large double values without rounding.

To learn more, see example below.

double
Index Integers
indexIntegers
boolean
Optional
Flag that indicates whether to index or omit indexing int32 and int64 type values. Value can be true or false. Either this or indexDoubles must be true. To learn more, see example below.
true
Index Doubles
indexDoubles
boolean
Optional
Flag that indicates whether to index or omit indexing double type values. Value can be true or false. Either this or indexIntegers must be true. To learn more, see example below.
true

The following index definition examples use multiple collections in the sample data. If you have the sample data already loaded on your cluster, you can use the Visual Editor and JSON Editor to configure these indexes. After you select your preferred configuration method, select the database and collection, and refine your index to add field mappings.

← knnVector