Analyze on text field


(Prashant Mishra) #1

https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/api-reference.html#api-msearch

I creating index using Bulk api from the above API references. where my type has a field with text which contains "." and alphanumeric. so want to make this field not_analyzed.

myidext/_anayzed

{
"field": "subfamilycode",
"text": "ENS.08.004.S20"
}

returns
{
"tokens": [
{
"token": "ens",
"start_offset": 0,
"end_offset": 3,
"type": "",
"position": 0
},
{
"token": "08.004",
"start_offset": 4,
"end_offset": 10,
"type": "",
"position": 1
},
{
"token": "s20",
"start_offset": 11,
"end_offset": 14,
"type": "",
"position": 2
}
]
}

i want it as
{
"tokens": [
{
"token": "ENS.08.004.S20",
"start_offset": 0,
"end_offset": 3,
"type": "",
"position": 0
}
}


(Thomas Dasch) #2

Someone please correct me if I am wrong. I believe you need to use a "keyword" analyzer which uses the "keyword" tokenizer. The doc https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-keyword-analyzer.html.


(Ivan Brusic) #3

It is even easier if you simply set the type of the field to be "keyword". No special analysis needed. https://www.elastic.co/guide/en/elasticsearch/reference/master/keyword.html


(Prashant Mishra) #4

@Ivan and @tdasch thank you, But the Javascript api is not allowing to put the mapping before index creation..

Please see the listed API url Above. There is function "client.indices.putMapping(....)".
If i am wrong then please correct me.


(Thomas Dasch) #5

Can you post the error you are getting please?


(Prashant Mishra) #6

@tdasch below error is coming if index is not created and i am trying to put the mapping.

Error: [index_not_found_exception] no such index, with { resource.type="index_or_alias" & resource.id="my_index_name" & index_uuid="na" & index="my_index_name" } :: {"path":"/my_index_name/_mapping/my_type","query":{},"body":"{"properties":{"code":{"type":"keyword","index":"not_analyzed"},"fcode":{"fielddata":true,"fields":{"raw":{"index":"not_analyzed","type":"string"}},"type":"string"},"title":{"fielddata":true,"fields":{"raw":{"index":"not_analyzed","type":"string"}},"type":"string"},"sfcode":{"fielddata":true,"fields":{"raw":{"index":"not_analyzed","type":"string"}},"type":"string"},"cLCode":{"fielddata":true,"fields":{"raw":{"index":"not_analyzed","type":"string"}},"type":"string"}}}","stCode":404,"response":"{"error":{"root_cause":[{"type":"index_not_found_exception","reason":"no such index","resource.type":"index_or_alias","resource.id":"my_index_name","index_uuid":"na","index":"my_index_name"}],"type":"index_not_found_exception","reason":"no such index","resource.type":"index_or_alias","resource.id":"my_index_name","index_uuid":"na","index":"my_index_name"},"status":404}"}

Even if i insert all records using the "BULK API" then "Code" field is set as text type and later it not allowing to change into type "keyword" by put mapping.


(Thomas Dasch) #7

Prashant,

I wonder if this link might help with the mapping problem? https://stackoverflow.com/questions/22325708/elasticsearch-create-index-with-mappings-using-javascript


(system) #8

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