Create mapping


(Toujou Aya) #1

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

'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.


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 .


(Adrien Grand) #2

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

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

(Toujou Aya) #3

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


(Adrien Grand) #4

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


(Toujou Aya) #5

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}

(Adrien Grand) #6

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


(Toujou Aya) #7

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


(Basem Khirat) #8

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

"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


(system) #9

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