PeeWee2201
PeeWee2201

Reputation: 1524

Set index=false through dynamic mapping for all float values

I wanted to setup mapping so that any unknown field of type float automatically got the property index=false.

I used the following request:

PUT /myindex/_mapping/mytype
{
    "dynamic_templates": [
      { "quantity": {
        "match": "*", 
        "match_mapping_type": "float",
        "mapping": {
          "index": "false"
        }
      }}
    ],
    "properties": {
      "ELEMENT_ID": {
        "type": "long",
        "index": "true"
      },
      "ELEMENT_TYPE": {
        "type": "keyword",
        "index": "true"
      }
    }
}

However the unknown fields remain searchable:

GET /myindex/mytype/_search
{
  "query": {
    "term": { "FEEDBACK_I": "0.8202897" }
  }
}

Is it possible to achieve this?

Thanks!

Upvotes: 0

Views: 147

Answers (1)

Andrei Stefan
Andrei Stefan

Reputation: 52368

I suggest this approach instead (ES is more likely to match your float to a double). And, also, index property has an allowed value of no in 1.x and 2.x and true/false in 5.x:

PUT /myindex/mytype/_mapping
{
  "mytype": {
    "dynamic_templates": [
      {
        "quantity": {
          "match": "*",
          "match_mapping_type": "double",
          "mapping": {
            "type": "double",
            "index": "no"
          }
        }
      },
      {
        "quantity_float": {
          "match": "*",
          "match_mapping_type": "float",
          "mapping": {
            "type": "float",
            "index": "no"
          }
        }
      }
    ]
  }
}

Upvotes: 1

Related Questions