【发布时间】:2017-01-15 11:22:08
【问题描述】:
我对弹性搜索有疑问。索引中有一个项目(“'title': 'Using Python with Elasticsearch'”)。只有搜索确切的查询,我才能得到返回的结果。但是,当我搜索“'title': 'Using Python with'”时,代码什么也没有。
es 版本为:{u'cluster_name': u'elasticsearch', u'tagline': u'You Know, for Search', u'version': {u'lucene_version': u'5.4.1', u' build_hash': u'd045fc29d1932bce18b2e65ab8b297fbf6cd41a1', u'number': u'2.2.1', u'build_timestamp': u'2016-03-09T09:38:54Z', u'build_snapshot': False}, u'name' : u'Lorelei Travis'}
如果我是对的,应该是 es 2.2.1。附上代码。那么,当我使用“Using Python with”之类的查询进行搜索时,我如何才能获得成功,而没有完全匹配的查询。谢谢!
INDEX_NAME = 'test_11'
from elasticsearch import Elasticsearch
es = Elasticsearch()
print es.info()
request_body = {
"mappings":{
"post":{
"properties":{
"title":{
"type":"string",
"index":"analyzed"
}
}
}
}
}
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)
print res
es.index(index=INDEX_NAME, doc_type='post', id=1, body={
'title': 'Using Python with Elasticsearch'
}
)
es.indices.refresh(index=INDEX_NAME)
res = es.search(index=INDEX_NAME, body={'query': {'match': {'title': 'Using Python with Elasticsearch'}}})
#res = es.search(index=INDEX_NAME, body ={"query":{"match":{"title":"Using Python with"}}})
print '\n'
res = es.indices.get(index=INDEX_NAME)
print res
【问题讨论】:
标签: python elasticsearch