_elastic$search%
来源:互联网 发布:买二手手机的软件 编辑:程序博客网 时间:2024/05/26 19:19
elasticsearch安装配置及中文分词 http://nosql.51document.com/1368777502778.html
linux下ElasticSearch(es)安装使用部署http://www.51document.com/1364910818272.html
Diving Into ElasticSearch (3) 编写自定义分词插件
http://log.medcl.net/item/2011/07/diving-into-elasticsearch-3-custom-analysis-plugin/
http://www.elasticsearch.org/
pip下载与安装
http://www.pip-installer.org/en/latest/installing.html
搜索引擎–elasticsearch python客户端pyes 建立索引和搜索
http://blog.csdn.net/yming0221/article/details/12228013
pyes文档
http://pyes.readthedocs.org/en/latest/
python 查找
http://nullege.com/codes/show/src@d@j@django-searchify-0.4@searchify@clients@pyes_client.py/339/pyes.CustomScoreQuery
elasticsearch配置
http://blog.csdn.net/laigood/article/details/7421197
http://www.cnblogs.com/MrHiFiy/archive/2012/12/06/2804334.html
http://wenku.baidu.com/view/e61be80090c69ec3d5bb75ae.html
主机环境:Ubuntu 13.04
中文站点:http://es-cn.medcl.net/
下面一段介绍引用自中文站点:
好吧,假如你建了一个web站点或者是一个应用程序,你就可能会需要添加搜索功能(因为这太有必要了),而事实上让搜索跑起来是有难度的,我们不仅想要搜索的速度快,而且还要安装方便(最好是无痛安装),另外模式定义要非常自由(schema free),可以通过HTTP以JSON格式的数据来进行索引,服务器必须是一直可用的(HA高可用,这个不能丢),从一台机器能够扩展到成千上万台,然后搜索必须是实时的(real-time),使用起来一定要简单、支持多租户,我们需要一整套的解决方案,并且是为云构建的。
“让搜索更简单”,这是我们的宣言,“并且要酷,像盆景一样”
elasticsearch 的目标是解决上面的所有问题以及更多。她是开源的(Apache2协议),分布式的,RESTful的,构建在Apache Lucene之上的的搜索引擎.
1
pip install pyes
1
index:
2
analysis:
3
analyzer:
4
ik:
5
alias: [ik_analyzer]
6
type: org.elasticsearch.index.analysis.IkAnalyzerProvider
- cd /etc/elasticsearch
- wget http://github.com/downloads/medcl/elasticsearch-analysis-ik/ik.zip –no-check-certificate
- unzip ik.zip
- rm ik.zip
01
#!/usr/bin/env python
02
#-*- coding:utf-8-*-
03
import
os
04
import
sys
05
from
pyes
import
*
06
07
INDEX_NAME
=
'txtfiles'
08
09
class
IndexFiles(
object
):
10
def
__init__(
self
,root):
11
conn
=
ES(
'127.0.0.1:9200'
, timeout
=
3.5
)
#连接ES
12
try
:
13
conn.delete_index(INDEX_NAME)
14
#pass
15
except
:
16
pass
17
conn.create_index(INDEX_NAME)
#新建一个索引
18
19
#定义索引存储结构
20
mapping
=
{u
'content'
: {
'boost'
:
1.0
,
21
'index'
:
'analyzed'
,
22
'store'
:
'yes'
,
23
'type'
: u
'string'
,
24
"indexAnalyzer"
:
"ik"
,
25
"searchAnalyzer"
:
"ik"
,
26
"term_vector"
:
"with_positions_offsets"
},
27
u
'name'
: {
'boost'
:
1.0
,
28
'index'
:
'analyzed'
,
29
'store'
:
'yes'
,
30
'type'
: u
'string'
,
31
"indexAnalyzer"
:
"ik"
,
32
"searchAnalyzer"
:
"ik"
,
33
"term_vector"
:
"with_positions_offsets"
},
34
u
'dirpath'
: {
'boost'
:
1.0
,
35
'index'
:
'analyzed'
,
36
'store'
:
'yes'
,
37
'type'
: u
'string'
,
38
"indexAnalyzer"
:
"ik"
,
39
"searchAnalyzer"
:
"ik"
,
40
"term_vector"
:
"with_positions_offsets"
},
41
}
42
43
conn.put_mapping(
"test-type"
, {
'properties'
:mapping}, [INDEX_NAME])
#定义test-type
44
45
self
.addIndex(conn,root)
46
47
conn.default_indices
=
[INDEX_NAME]
#设置默认的索引
48
conn.refresh()
#刷新以获得最新插入的文档
49
50
def
addIndex(
self
,conn,root):
51
print
root
52
for
root, dirnames, filenames
in
os.walk(root):
53
for
filename
in
filenames:
54
if
not
filename.endswith(
'.txt'
):
55
continue
56
print
"Indexing file "
, filename
57
try
:
58
path
=
os.path.join(root,filename)
59
file
=
open
(path)
60
contents
=
unicode
(
file
.read(),
'utf-8'
)
61
file
.close()
62
if
len
(contents) >
0
:
63
conn.index({
'name'
:filename,
'dirpath'
:root,
'content'
:contents},INDEX_NAME,
'test-type'
)
64
else
:
65
print
'no contents in file %s'
,path
66
except
Exception,e:
67
print
e
68
69
if
__name__
=
=
'__main__'
:
70
IndexFiles(
'./txtfiles'
)
01
#!/usr/bin/env python
02
#-*- coding:utf-8 -*-
03
04
import
os
05
import
sys
06
from
pyes
import
*
07
08
conn
=
ES(
'127.0.0.1:9200'
, timeout
=
3.5
)
#连接ES
09
sq
=
StringQuery(u
'世界末日'
,
'content'
)
10
h
=
HighLighter([
'<b>'
], [
'</b>'
], fragment_size
=
20
)
11
12
s
=
Search(sq,highlight
=
h)
13
s.add_highlight(
"content"
)
14
results
=
conn.search(s,indices
=
'txtfiles'
,doc_types
=
'test-type'
)
15
16
list
=
[]
17
for
r
in
results:
18
if
(r._meta.highlight.has_key(
"content"
)):
19
r[
'content'
]
=
r._meta.highlight[u
"content"
][
0
]
20
list
.append(r)
21
print
r[
'content'
]
22
print
len
(
list
)
- _elastic$search%
- ElasticSearch学习28_Elastic中国开发者大会2016介绍
- Search
- search
- search
- search
- search
- Search
- search
- Search
- Search
- search
- search
- Search
- search
- search
- Search
- search
- POI另存数据至Excel文件
- Asp.net生命周期代码呈现过程
- 关于函数调用基本知识
- MFC中CString转换成char数组的问题
- 黑马程序员_银行业务调度学习总结
- _elastic$search%
- Java上实现RESTful Web Services
- 2013-10-9 android 打包工具和测试
- 每个 MySQL 开发者都应该了解的 12 个技巧
- 新视野OJ 2705 [SDOI2012]Longge的问题 (数论)
- 最近技术方向有点乱
- android 屏幕适配问题
- Oracle虚拟化设备曝光 挑战NetApp和EMC
- Insert数据的方法