elasticsearch学习

来源:互联网 发布:建筑三维制图软件 编辑:程序博客网 时间:2024/06/12 10:51

centos安装 

http://www.cnblogs.com/kravis/p/5824897.html

5.4以上需要jdk1.8以上版本


curl -XGET 'http://localhost:9200'


3)用root用户运行es会报错
  Exception in thread "main" java.lang.RuntimeException: don't run elasticsearch as root. 
  at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:93) 
  at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:144)
  at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:285) 
  at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:35) 
  Refer to the log for complete error details.

由于ElasticSearch可以接收用户输入的脚本并且执行,为了系统安全考虑, 建议创建一个单独的用户用来运行ElasticSearch
  groupadd elsearch
  useradd elsearch -g elsearch -p elasticsearch

更改elasticsearch文件夹及内部文件的所属用户及组为elsearch:elsearch

  cd /opt
  chown -R elsearch:elsearch elasticsearch


运行错误

http://blog.csdn.net/u012246178/article/details/63253531

切换到elsearch用户再启动
  su elsearch cd elasticsearch/bin
  ./elasticsearch



elasticsearch5.0以上的插件,需要安装node.js



5.0之后的版本可以安装kibana作为管理配置平台

http://blog.csdn.net/dm_vincent/article/details/41693125

删除索引

DELETE /my-index

添加文档,索引重复的内容添加失败,但是更新成功, 不同的索引添加成功

PUT /gateway/help/1
{
  "title": "如何添加分组", 
  "answer": "提交jira,通过审核后由管理员添加"
}


"result": "updated",


查找

GET /apihelp/help/_search
{
    "query" : {
        "match" : {
            "answer" : "张三"
        }
    }
}

提示: 做精确匹配搜索时,你最好用过滤语句,因为过滤语句可以缓存数据。

match查询只能就指定某个确切字段某个确切的值进行搜索,而你要做的就是为它指定正确的字段名以避免语法错误。


多字段查找

GET _search{

  "query": {
    "multi_match": { 
        "query":    "分组管理员", 
        "fields":   [ "title", "answer" ] 
    }
  }
}


python 调用ES 

参考http://www.tuicool.com/articles/qaeqY3

    #多字段查询
    res = es.search(apiHelpIndex, body={"query": {"multi_match":  {"query":"分组管理员","fields":   [ "title", "answer" ]}}})
    print res['hits']['hits'][0]['_source']['answer'].decode('utf8')
    strRes = json.dumps(res, ensure_ascii=False)
    print strRes.decode('utf-8')





0 0