`

ElasticSearch Install

    博客分类:
  • ELK
 
阅读更多

1.下载安装文件

假如我们下载到/opt/elk目录

wget https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/tar/elasticsearch/2.3.3/elasticsearch-2.3.3.tar.gz

2.解压安装文件

假如我们解压到/opt/elk目录

tar zxvf elasticsearch-2.3.3.tar.gz

3.修改elasticsearch.yml

打开/opt/elk/elasticsearch-2.3.3/config/elasticsearch.yml,修改配置内容如下:

cluster.name: goeasy-dev
node.name: goeasy-dev-node1
network.host: 192.168.1.10
http.port: 9200

4.新建Linux用户

由于elasticsearch不能用root用户启动,因此我们需要新建一个用户来启动它

 a. 使用useradd命令创建一个用户,并设置登录密码

useradd phy
passwd phy
输入新密码

b.给新建的用户分配目录权限

假如/opt/elk/elasticsearch-2.3.3是我们安装的目录,那需要把这个目录的权限分配给用户

chown -R phy:phy /opt/elk/elasticsearch-2.3.3

5.启动ElasticSearch

 a. 使用su命令从root用户切换到phy用户

su phy
输入密码

b. 打开/opt/elk/elasticsearch-2.3.3目录,然后运行:

bin/elasticsearch
 
#如果想在后台运行,可以增加-d
bin/elasticsearch -d

6.测试

在浏览器中输入http://192.168.1.10:9200/  ,如果能看到下面返回信息,说明elasticsearch安装成功了

{
  "name" "goeasy-dev-node1",
  "cluster_name" "goeasy-dev",
  "version" : {
    "number" "2.3.3",
    "build_hash" "218bdf10790eef486ff2c41a3df5cfa32dadcfde",
    "build_timestamp" "2016-05-17T15:40:04Z",
    "build_snapshot" false,
    "lucene_version" "5.5.0"
  },
  "tagline" "You Know, for Search"
}

 

参考文档:

https://www.elastic.co/guide/en/elasticsearch/reference/current/setup.html

 

附:Java操作ElastchSearch代码:

package com.yhiker.search;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.HashMap;
import java.util.Map;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.index.query.MatchQueryBuilder.Operator;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.SearchHit;
import com.lm.core.util.JsonUtils;
import com.lm.core.util.ValueUtils;
public class Test {
    private static Client client = null;
    static {
        init();
    }
    private static void init() {
        if (client != null) {
            return;
        }
        try {
             
            Map<String,String> settingsMap = new HashMap<String,String>();
            settingsMap.put("cluster.name""goeasy-dev");
            settingsMap.put("client.transport.sniff""true");
             
             
            Settings settings = Settings.settingsBuilder().put(settingsMap).build();
            client = TransportClient.builder().settings(settings).build()
                    .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("192.168.1.10"), 9300));
             
        catch (UnknownHostException e) {
            e.printStackTrace();
        }
    }
     
    public static void createIndex(Goods goods) {
        System.out.println("==============createIndex=============");
         
        String json = JsonUtils.toJson(goods);
        IndexResponse response = client.prepareIndex("goeasy""goods", ValueUtils.toString(goods.getId())).setSource(json).get();
        // Index name
        String _index = response.getIndex();
        System.out.println("_index=" + _index);
        // Type name
        String _type = response.getType();
        System.out.println("_type=" + _type);
        // Document ID (generated or not)
        String _id = response.getId();
        System.out.println("_id=" + _id);
        // Version (if it's the first time you index this document, you will
        // get: 1)
        long _version = response.getVersion();
        System.out.println("_version=" + _version);
        // isCreated() is true if the document is a new one, false if it has
        // been updated
        boolean created = response.isCreated();
        System.out.println("created=" + created);
    }
     
    public static void createGoodsIndex(int id,String title,String description,String category,String brand){
        Goods goods = new Goods();
        goods.setId(id);
        goods.setTitle(title);
        goods.setDescription(description);
        goods.setCategory(category);
        goods.setBrand(brand);
        createIndex(goods);
    }
     
    public static void crateGoodsIndex(){
        createGoodsIndex(1,"台南府城盐咖啡","【台湾第一盐咖啡】台南府城盐咖啡 时尚独特 香浓细腻","美食佳品","雀巢");
        createGoodsIndex(2,"我的心机 玻尿酸保湿锁水黑面膜 8片","【强效锁水】我的心机 玻尿酸保湿锁水黑面膜 8片 深度补水,海客","美妆个护","我的心机");
        createGoodsIndex(3,"我的心机 仙人掌精粹补水黑面膜 8片","【补水神器】我的心机 仙人掌精粹补水黑面膜 8片 补水急救","美妆个护","我的心机");
        createGoodsIndex(4,"糖村法式牛轧糖 500g","【高圆圆的喜糖】糖村法式牛轧糖 500g 新鲜美味","美食佳品","糖村");
        createGoodsIndex(5,"糖村法式牛轧糖 250g","【最好吃的牛扎糖】糖村法式牛轧糖 250g 新鲜美味","美食佳品","糖村");   
    }
     
    public static void search(){
        SearchResponse response = client.prepareSearch("goeasy")
                .setTypes("goods")
                .setQuery(QueryBuilders.multiMatchQuery("美食""title","description","category","brand").operator(Operator.AND))
                .execute()
                .actionGet();
     
        System.out.println(response.toString());
         
        SearchHit[] hits = response.getHits().getHits();
        for(SearchHit hit:hits){
             System.out.println(hit.sourceAsString());
        }
    }
     
    public static void main(String[] args) {
        //crateGoodsIndex();
        //search();
    }
}

 

分享到:
评论

相关推荐

    elasticsearch-shield-2.3.2.jar

    1、进入到Elasticsearch的安装路径下,本文中以该路径为例子:/ultra/ES/elasticsearch-2.3.4。先安装license,执行以下命令: ./bin/plugin install license 2、再安装shield,执行以下命令: ./bin/plugin ...

    elasticsearch-sql安装使用文档.docx

    如果我们安装不成功,我们可以直接下载 Elasticsearch-SQL 插件的压缩包,然后解压,完成之后重命名文件夹为 sql ,放到 ES 的安装路径的 plugins目录中,例如:..\elasticsearch-6.4.0\plugins\sql。

    Elasticsearch hanlp 分词插件

    然后执行 elasticsearch-plugin.bat install file:///E:/elasticsearch-analysis-ik-6.4.2.zip Linux下安装命令 首先进入bin目录,然后执行 ./plugin install file:///home/xxx/elasticsearch-analysis-ik-6.4.2....

    Packt.Monitoring.ElasticSearch.1784397806.pdf

    You will then see how to install and configure ElasticSearch and the ElasticSearch monitoring plugins. Then, you will proceed to install and use the Marvel dashboard to monitor ElasticSearch. You ...

    install-elasticsearch-cluster.sh

    一键安装elasticsearch脚本,Elasticsearch 是位于 Elastic Stack 核心的分布式搜索和分析引擎。Logstash 和 Beats 有助于收集、聚合和丰富您的数据并将其存储在 Elasticsearch 中。Kibana 使您能够以交互方式探索、...

    elasticsearch in action

    Elasticsearch makes it easy to add efficient and scalable searches to enterprise applications. Busy administrators and developers love this open source real-time search and analytics engine because ...

    Monitoring ElasticSearch

    You will then see how to install and configure ElasticSearch and the ElasticSearch monitoring plugins. Then, you will proceed to install and use the Marvel dashboard to monitor ElasticSearch. You ...

    Learning Elasticsearch 【含代码】

    You will install and set up Elasticsearch and its related plugins, and handle documents using the Distributed Document Store. You will see how to query, search, and index your data, and perform ...

    Packt.Learning.Elasticsearch.pdf

    You will see how to install Elasticsearch and Kibana and learn how to index and update your data. We will use an e-commerce site as an example to explain how a search engine works and how to query ...

    ElasticSearch环境搭建详细步骤

    本文档提供了ElasticSearch的详细安装说明,包括Head、和IK分词插件。 1、安装ElasticSearch 安装ElasticSearch的前提条件:JDK1.8及以上 ElasticSearch安装文件的下载地址为 ...

    elasticsearch-5.6.7

    ElasticSearch是一个基于Lucene的搜索服务器。它提供了一个分布式多用户能力的全文搜索引擎,基于RESTful web接口。Elasticsearch是用Java开发的,并作为Apache许可条款下的开放源码发布,是当前流行的企业级搜索...

    Elasticsearch.A.Complete.Guide.epub

    Install and configure Elasticsearch, Logstash, and Kibana Write CRUDE operations and other search functionalities using the Elasticsearch Python and Java Clients Build analytics using aggregations Set...

    ElasticSearch+Django+Scrapy搜索引擎

    scrapy爬虫获取数据存储至es,ElasticSearch+Django实现搜索页面。 快速开始 # 下拉项目代码 git clone https://github.com/downdawn/eswork.git # 安装requirements.txt依赖 pip install -r requirements.txt # ...

    基于ElasticSearch的Communism全文搜索引擎

    基于ElasticSearch的Communism全文搜索引擎 依赖环境 Python 3.7(建议直接使用 Anaconda ) ElasticSearch 7.5.0 (核心依赖组件) MySQL 8.0 (目前不是强制需要) 安装方式 下载项目源码到本地,并进入根目录 ...

    基于elasticsearch的电影搜索引擎

    &gt; elasticsearch-plugin install # 启动elasticsearch &gt; bin/elasticsearch # 设置虚拟环境 &gt; python -m venv env &gt; source env/bin/activate &gt; pip install -r requirements.txt # 启动爬虫 # 数据自动送入...

    elasticsearch-head-master.rar

    用于elasticSearch。ealsticsearch只是后端提供各种api,那么怎么直观的使用它呢?elasticsearch-head将是一款专门针对于elasticsearch的客户端工具。 npm install npm run start open http://localhost:9100/ ...

    elasticsearch-analysis-ik 和elasticsearch-analysis-mmseg

    分布式搜索elasticsearch1.1.0版本 中文分词集成,现在不支持bin/plugin -install medcl/elasticsearch-analysis-ik/1.1.0 版本的安装,直接解压安装ik和mmseg插件,看博文

    Elasticsearch​的ORM工具orm4es.zip

    orm4es是一个Elasticsearch的ORM工具,它可以生成简单的查询对象.它本身非常简单,也很容易使用;代码生成通过freemark完成,它会自动解析es index 的mapping设置,根据mapping生成与index对应的java Bean,使用生成...

    elasticsearch_loader:用于将数据文件(json,parquet,csv,tsv)批量加载到ElasticSearch的工具

    elasticsearch_loader 主要特点 批量上传CSV(实际上是任何* SV)文件到Elasticsearch 批量上传JSON文件/ JSON行到Elasticsearch 将镶木地板文件批量上传到Elasticsearch 预定义自定义映射 上传前删除索引 使用...

    Monitoring ElasticSearch(PACKT,2016)

    You will then see how to install and configure ElasticSearch and the ElasticSearch monitoring plugins. Then, you will proceed to install and use the Marvel dashboard to monitor ElasticSearch. You ...

Global site tag (gtag.js) - Google Analytics