Skip to content

Commit

Permalink
Added queries for mapping section
Browse files Browse the repository at this point in the history
  • Loading branch information
ba0708 committed Jul 9, 2017
1 parent d82f7cf commit 3661c6b
Show file tree
Hide file tree
Showing 6 changed files with 216 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Mapping/adding-mappings-to-existing-indices.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Adding mappings to existing indices

## Adding mapping for `discount` field

```
PUT /product/default/_mapping
{
"properties": {
"discount": {
"type": "double"
}
}
}
```

## Retrieving mapping

```
GET /product/default/_mapping
```
36 changes: 36 additions & 0 deletions Mapping/adding-multi-fields-mappings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Adding multi-fields mappings

## Adding mappings

```
PUT /product/default/_mapping
{
"properties": {
"description": {
"type": "text"
},
"name": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
}
},
"tags": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
}
}
}
}
```

## Retrieving mapping

```
GET /product/default/_mapping
```
34 changes: 34 additions & 0 deletions Mapping/changing-existing-mappings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Changing existing mappings

## Deleting the index

```
DELETE /product
```

## Creating index with mappings

```
PUT /product
{
"mappings": {
"default": {
"dynamic": false,
"properties": {
"in_stock": {
"type": "integer"
},
"is_active": {
"type": "boolean"
},
"price": {
"type": "integer"
},
"sold": {
"type": "long"
}
}
}
}
}
```
57 changes: 57 additions & 0 deletions Mapping/defining-custom-date-formats.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Defining custom date formats

## Date mapping with `year` format

```
PUT /product/default/_mapping
{
"properties": {
"created": {
"type": "date",
"format": "year"
}
}
}
```

## Date mapping with `strict_year` format

```
PUT /product/default/_mapping
{
"properties": {
"created": {
"type": "date",
"format": "strict_year"
}
}
}
```

## Date mapping with explicit default format

```
PUT /product/default/_mapping
{
"properties": {
"created": {
"type": "date",
"format": "strict_date_optional_time||epoch_millis"
}
}
}
```

## Date mapping with date and optional time

```
PUT /product/default/_mapping
{
"properties": {
"created": {
"type": "date",
"format": "yyyy/MM/dd HH:mm:ss||yyyy/MM/dd"
}
}
}
```
7 changes: 7 additions & 0 deletions Mapping/dynamic-mapping.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Dynamic mapping

## Retrieving mapping

```
GET /product/default/_mapping
```
62 changes: 62 additions & 0 deletions Mapping/picking-up-new-fields-without-dynamic-mapping.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Picking up new fields without dynamic mapping

## Adding test document

```
POST /product/default/2000
{
"description": "Test",
"discount": 20
}
```

## Adding mapping for `discount` field

```
PUT /product/default/_mapping
{
"properties": {
"discount": {
"type": "integer"
}
}
}
```

## Querying the `description` field

```
GET /product/default/_search
{
"query": {
"match": {
"description": "Test"
}
}
}
```

## Querying the `discount` field

```
GET /product/default/_search
{
"query": {
"term": {
"discount": 20
}
}
}
```

## Picking up new mappings for documents

```
POST /product/_update_by_query?conflicts=proceed
```

## Deleting the test document

```
DELETE /product/default/2000
```

0 comments on commit 3661c6b

Please sign in to comment.