Skip to content

Instantly share code, notes, and snippets.

@ycombinator
Last active January 4, 2017 19:49
Show Gist options
  • Save ycombinator/757cd9cd7303933abf3bc3b7e477c1fd to your computer and use it in GitHub Desktop.
Save ycombinator/757cd9cd7303933abf3bc3b7e477c1fd to your computer and use it in GitHub Desktop.

Install the murmur3 plugin

./bin/elasticsearch-plugin install mapper-murmur3

Add a new field with a multi-field using the murmur3 type

PUT foo/_mapping/bar
{
  "properties": {
    "qux": {
      "type": "text",
      "fields": {
        "hash": {
          "type": "murmur3"
        }
      }
    }
  }
}

Index some data in the qux field

POST foo/bar/2
{
  "qux": "Lorem ipsum elastic audio technica glad"
}

Get field stats for this index

GET foo/_field_stats?fields=*&pretty

Note that no object is returned for the qux.hash field

Add a new field with a multi-field using a built-in type

PUT foo/_mapping/bar
{
  "properties": {
    "boop": {
      "type": "text",
      "fields": {
        "raw": {
          "type": "keyword"
        }
      }
    }
  }
}

Index some data in the boop field

POST foo/bar/3
{
  "boop": "Lorem ipsum elastic audio technica glad errand math"
}

Get field stats for this index

GET foo/_field_stats?fields=*&pretty

Note that an object is returned for the boop.raw field

Create an index with a text field

PUT foo
{
  "mappings": {
    "bar": {
      "properties": {
        "baz": {
          "type": "text"
        }
      }
    }
  }
}

Get field stats for this index

GET foo/_field_stats?fields=*&pretty

Note that no object is returned for the baz field as there is no data.

Index some data in the baz field

POST foo/bar/1
{
  "baz": "Lorem ipsum elastic"
}

Get field stats for this index

GET foo/_field_stats?fields=*&pretty

Note that an object is returned for the baz field now that there is data.

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