当前位置: 首页 > news >正文

web后端是做什么的/北京网站优化方式

web后端是做什么的,北京网站优化方式,asp网站建设实录,做网站政府扶持既然是开发篇,主要以代码为主,辅助一些说明。所有的内容都是代码实际应该验证过的。 引入的头文件: import static org.elasticsearch.node.NodeBuilder.nodeBuilder;import java.io.IOException; import java.net.InetAddress; import java.…

既然是开发篇,主要以代码为主,辅助一些说明。所有的内容都是代码实际应该验证过的。

引入的头文件:

import static org.elasticsearch.node.NodeBuilder.nodeBuilder;import java.io.IOException;
import java.net.InetAddress;
import java.util.Date;
import java.util.Map;
import java.util.Set;import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder;
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.ClusterAdminClient;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.cluster.health.ClusterIndexHealth;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.node.Node;
import static org.elasticsearch.common.xcontent.XContentFactory.*;


创建索引

XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject("settings").field("number_of_shards", 1)//设置分片数量.field("number_of_replicas", 0)//设置副本数量.endObject().endObject().startObject().startObject(type)//type名称.startObject("properties") //下面是设置文档列属性。.startObject("type").field("type", "string").field("store", "yes").endObject().startObject("eventCount").field("type", "long").field("store", "yes").endObject().startObject("eventDate").field("type", "date").field("format", "dateOptionalTime").field("store", "yes").endObject().startObject("message").field("type", "string").field("index", "not_analyzed").field("store", "yes").endObject().endObject().endObject().endObject();CreateIndexRequestBuilder cirb = client.admin().indices().prepareCreate(indexName)//index名称.setSource(mapping);CreateIndexResponse response = cirb.execute().actionGet();
if (response.isAcknowledged()) {System.out.println("Index created.");
} else {System.err.println("Index creation failed.");
}


增加文档

IndexResponse response = client.prepareIndex(indexName, type, "1").setSource(//这里可以直接用json字符串jsonBuilder().startObject().field("type", "syslog").field("eventCount", 1).field("eventDate", new Date()).field("message", "secilog insert doc test").endObject()).get();
System.out.println("index:"+response.getIndex()+" insert doc id:"+response.getId()+" result:"+response.isCreated());


查询文档

GetResponse response = client.prepareGet("secilog", "log", "1").get();
String source = response.getSource().toString();
long version = response.getVersion();
String indexName = response.getIndex();
String type = response.getType();
String id = response.getId();


修改文档

修改文档有两种方式,一种是直接修改,另一种是如果文档不存在则插入存在则修改。

第一种代码

UpdateRequest updateRequest = new UpdateRequest();
updateRequest.index(indexName);
updateRequest.type(type);
updateRequest.id("1");
updateRequest.doc(jsonBuilder().startObject().field("type", "file").endObject());
client.update(updateRequest).get();


第二种代码:

IndexRequest indexRequest = new IndexRequest(indexName, type, "3")
.source(jsonBuilder().startObject().field("type", "syslog").field("eventCount", 2).field("eventDate", new Date()).field("message", "secilog insert doc test").endObject());
UpdateRequest updateRequest = new UpdateRequest(indexName, type, "3").doc(jsonBuilder().startObject().field("type", "file").endObject()).upsert(indexRequest);              
client.update(updateRequest).get();


删除文档

DeleteResponse dresponse = client.prepareDelete("secilog", "log", "4").get();
boolean isFound = dresponse.isFound(); //文档存在返回true,不存在返回false;


删除索引

DeleteIndexRequest delete = new DeleteIndexRequest("secilog");
client.admin().indices().delete(delete);


http://www.lbrq.cn/news/1331605.html

相关文章:

  • 做seo网站优化价格/360竞价推广登录入口
  • 安庆网站建设工作室/网络卖货平台有哪些
  • ui中国网站/优化深圳seo
  • java企业门户网站开发教程/山东16市最新疫情
  • 佛山专业网站设计/网络营销是什么专业类别
  • 北京常用网站/广州seo优化费用
  • 北京门户网站制作费用/百度seo公司哪家好一点
  • 有什么做衣服的网站吗/历下区百度seo
  • 360网站制作潍坊/厦门seo推广优化
  • 装潢公司网站源码php/网站优化排名首页
  • jsp做网站图片怎么存储/百度新闻头条
  • 网站开发项目可行性/nba交易最新消息
  • app开发学习网站/百度网盘app手机版
  • 微信商城与网站一体/google网址直接打开
  • 网站建设百灵鸟优化/百度快照是什么意思
  • 微信分享 淘宝网站 怎么做/万网域名官网
  • 初中信息科技怎么自己做网站/2023半夜免费b站推广
  • 新疆建设工程建设云官网/北京seo的排名优化
  • 定制型网站制作价格/html网页制作模板
  • 深圳网站搭建电话/东莞网络营销网站建设
  • 建设通网站账号/聊城今日头条最新
  • 无锡网络公司官网/河南郑州网站推广优化外包
  • 东游科技网站建设/赵阳竞价培训
  • wordpress 文章 来源/seo深圳网络推广
  • 网页设计公司开设需要投资多少钱/seo 公司
  • 网站开发w亿玛酷1专注/线上招生引流推广方法
  • 做优化的网站用什么空间好/营销方式有哪几种
  • 做网站需要备案吗/国内疫情最新情况
  • 网站开发页面/360关键词排名推广
  • htm网站制作/石家庄邮电职业技术学院
  • 【WRF-Chem教程第七期】闪电-NOx 参数化方案详解
  • JAVA后端开发——用 Spring Boot 实现定时任务
  • 电商项目_核心业务_分布式ID服务
  • CentOS网卡未被托管解决记录
  • 使用Spring Boot创建Web项目
  • 学习嵌入式的第三十二天-数据结构-(2025.7.24)IO多路复用