Hi, I am new to elasticsearch. There is an item in my index with the title: Using Python with Elasticsearch
When I search for it, I always get zero hit except that I search "Using Python with Elasticsearch" exactly.
like:
1, The code
import elasticsearch
INDEX_NAME= 'test_1'
from elasticsearch import Elasticsearch
es = Elasticsearch()
es.index(index=INDEX_NAME, doc_type='post', id=1, body={
'author': 'John Doe',
'blog': 'Learning Elasticsearch',
'title': 'Using Python with Elasticsearch',
'tags': ['python', 'elasticsearch', 'tips'],
})
es.indices.refresh(index=INDEX_NAME)
res = es.indices.get(index=INDEX_NAME)
print res
The output is:
{u'test_1': {u'warmers': {}, u'settings': {u'index': {u'number_of_replicas': u'1', u'number_of_shards': u'5', u'uuid': u'Z2KLxeQLRay4rFgdK4yo9A', u'version': {u'created': u'2020199'}, u'creation_date': u'1484405704970'}}, u'mappings': {u'post': {u'properties': {u'blog': {u'type': u'string'}, u'title': {u'type': u'string'}, u'tags': {u'type': u'string'}, u'author': {u'type': u'string'}}}}, u'aliases': {}}}
2, I change the mappings with the code below:
INDEX_NAME = 'test_1'
from elasticsearch import Elasticsearch
es = Elasticsearch()
request_body = {
'mappings':{
'post': {
'properties': {
'title': {'type':'text'}
}
}
}
}
if es.indices.exists(INDEX_NAME):
res = es.indices.delete(index = INDEX_NAME)
print(" response: '%s'" % (res))
res = es.indices.create(index = INDEX_NAME, body= request_body, ignore=400)
print res
The output is
response: '{u'acknowledged': True}'
{u'status': 400, u'error': {u'caused_by': {u'reason': u**'No handler for type [text] declared on field [title]**', u'type': u'mapper_parsing_exception'}, u'root_cause': [{u'reason': u'No handler for type [text] declared on field [title]', u'type': u'mapper_parsing_exception'}], u'type': u'mapper_parsing_exception', u'reason': u'Failed to parse mapping [post]: No handler for type [text] declared on field [title]'}}
3, I update the elasticsearch from 1.9 to (5, 1, 0, 'dev')
4, I also try to change the mappings with the code below
request_body = {
'mappings':{
'post': {
'properties': {
'title': {'type':'string', "index": "analyzed"}
}
}
}
}
but, it still cannot get the fuzzy match result!
Thanks a lot!!