# Create mapping

**URL:** https://discuss.elastic.co/t/create-mapping/82401
**Category:** Elasticsearch
**Created:** [April 14, 2017, 10:12am UTC](https://discuss.elastic.co/t/create-mapping/82401 "2017-04-14T10:12:20Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![ToujouAya](https://avatars.discourse-cdn.com/v4/letter/t/9fc29f/32.png) [@ToujouAya](https://discuss.elastic.co/u/ToujouAya)
#### Post date: [April 14, 2017, 10:12am UTC](https://discuss.elastic.co/t/create-mapping/82401/1 "2017-04-14T10:12:20Z")

</div>

Elasticsearch version: 5.3.0

Plugins installed: []

JVM version: 1.8.0\_121

OS version: windows 10

Description of the problem including expected versus actual behavior:  
There is my mapping code created in PHP

```auto
'mappings' => [
'items' => [
'attributes' => [
'type' => 'string'
]

            ]
        ]

```

attributes property is an object like this  
{ title : '', 'description' }

I want to sort in the title . But it show the error that I need to enable fielddata of titile.  
I have changed the config mapping many time but it's not working.

[![](https://cloud.githubusercontent.com/assets/21350606/25040501/f6c298a2-2133-11e7-9fbe-7b1d5e9fba0b.png) ](https://cloud.githubusercontent.com/assets/21350606/25040501/f6c298a2-2133-11e7-9fbe-7b1d5e9fba0b.png)  
I used basemkhirat/elasticsearch package to connect to elasticsearch serve.  
Does anyone have any idea to solve this case?  
Please help me. Sorry for my English  
Thank you .

---

<div class="post-metadata">

### Author: ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)
#### Post date: [April 14, 2017, 10:47am UTC](https://discuss.elastic.co/t/create-mapping/82401/2 "2017-04-14T10:47:07Z")

</div>

I guess you will want to do this instead if you only need to perform exact matching and sorting on this field.

```auto
'mappings' => [
  'items' => [
    'attributes' => [
      'type' => 'keyword'
    ]
  ]
]

```

---

<div class="post-metadata">

### Author: ![ToujouAya](https://avatars.discourse-cdn.com/v4/letter/t/9fc29f/32.png) [@ToujouAya](https://discuss.elastic.co/u/ToujouAya)
#### Post date: [April 17, 2017, 4:05am UTC](https://discuss.elastic.co/t/create-mapping/82401/3 "2017-04-17T04:05:57Z")

</div>

Thank you for your reply. Actually my attributes item is object contain some properties like that  
`'attributes' : { 'tittle' : '', 'des': '' }`  
I thought i need to change the mapping config , push the attribute properties inside the attribute like this:

```
`'mappings' => ['items' => ['attributes' => ['type' => 'string' , 'fields' => ['title' => ['type' => 'keyword']]] ]]`

```

But it is not work,May be it is not correct.

So i have changed the mapping again move the these properties to outside the attributes item . Make it is like item.

```
`mappings => ['items' => ['title' => ['type' => 'keyword', 'fielddata' => true]]]`

```

with that config I can sort the title.

But i don't know this way is best config or not

---

<div class="post-metadata">

### Author: ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)
#### Post date: [April 18, 2017, 8:06am UTC](https://discuss.elastic.co/t/create-mapping/82401/4 "2017-04-18T08:06:11Z")

</div>

It looks good to me, I would just remove the `fielddata => true` part, which should not be necessary.

---

<div class="post-metadata">

### Author: ![ToujouAya](https://avatars.discourse-cdn.com/v4/letter/t/9fc29f/32.png) [@ToujouAya](https://discuss.elastic.co/u/ToujouAya)
#### Post date: [April 18, 2017, 8:12am UTC](https://discuss.elastic.co/t/create-mapping/82401/5 "2017-04-18T08:12:18Z")

</div>

If i remove the `fileddata => true` I can't sort for `title` or `des` it always show error that I need to enable `fielddata`

```
{"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"Fielddata is disabled on text fields by default. Set fielddata=true on [title] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory."}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"query","grouped":true,"failed_shards":[{"shard":0,"index":"item_index","node":"a3gMQwzKRZutgHZI7qC4bA","reason":{"type":"illegal_argument_exception","reason":"Fielddata is disabled on text fields by default. Set fielddata=true on [title] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory."}}],"caused_by":{"type":"illegal_argument_exception","reason":"Fielddata is disabled on text fields by default. Set fielddata=true on [title] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory."}},"status":400}
```

---

<div class="post-metadata">

### Author: ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)
#### Post date: [April 18, 2017, 8:37am UTC](https://discuss.elastic.co/t/create-mapping/82401/6 "2017-04-18T08:37:55Z")

</div>

It means that `type: keyword` is being ignored somehow and you field is actually mapped as `type:text`.

---

<div class="post-metadata">

### Author: ![ToujouAya](https://avatars.discourse-cdn.com/v4/letter/t/9fc29f/32.png) [@ToujouAya](https://discuss.elastic.co/u/ToujouAya)
#### Post date: [April 18, 2017, 8:59am UTC](https://discuss.elastic.co/t/create-mapping/82401/7 "2017-04-18T08:59:11Z")

</div>

Oh I missed some point.  
Your way works correct. Thanks

Could you give me some idea,  
I used regexp to searching, If I config mapping like you said but I can't get any research

if i used my config I can get result

My config

```
{ "item_index": {
"mappings": {
  "items": {
    "properties": {
      "description": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword"
          }
        },
        "analyzer": "standard",
        "fielddata": true
      },
      "image": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword"
          }
        },
        "analyzer": "standard",
        "fielddata": true
      },
      "menus": {
        "type": "long"
      },
      "name": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
      "title": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword"
          }
        },
        "analyzer": "standard",
        "fielddata": true
      }
    }
  }
} }}

```

param query regex at this link [Query params](https://pastebin.com/TnPVCt2B)

---

<div class="post-metadata">

### Author: ![basemkhirat](https://avatars.discourse-cdn.com/v4/letter/b/ec9cab/32.png) [@basemkhirat](https://discuss.elastic.co/u/basemkhirat)
#### Post date: [April 28, 2017, 2:09pm UTC](https://discuss.elastic.co/t/create-mapping/82401/8 "2017-04-28T14:09:15Z")

</div>

Please upgrade your package to version 1.0  
This is how you can set your mappings

```auto
"mappings" => [
	"items" => [
        "properties" => [
            "title" => [
                "type" => "string"
            ]
        ]
	]
]

```

In other point please note that in earlier versions, the artisan command `php artisan es:indices:create` & `php artisan es:indices:update` were linked with properties key directly so such as `_all` key and other keys out of properties key scope caused errors and not worked

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [May 26, 2017, 2:14pm UTC](https://discuss.elastic.co/t/create-mapping/82401/9 "2017-05-26T14:14:02Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
