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

超八成搜索网站存在信息泄露问题网易企业邮箱域名

超八成搜索网站存在信息泄露问题,网易企业邮箱域名,企业网站建设 电脑配置,天津网假设已基于docker搭建elasticsearch,详细过程参考如下链接。 https://blog.csdn.net/liliang199/article/details/151581138 这里先验证ES运行是否正常,然后导入向量数据,并示例查询过程。 1 安装验证 设置ES密码环境变量 export ELASTIC_P…

假设已基于docker搭建elasticsearch,详细过程参考如下链接。

https://blog.csdn.net/liliang199/article/details/151581138

这里先验证ES运行是否正常,然后导入向量数据,并示例查询过程。

1 安装验证

设置ES密码环境变量

export ELASTIC_PASSWORD=xxxxxx

如果忘记密码,可以重新生成一份

docker exec -it es01 /usr/share/elasticsearch/bin/elasticsearch-reset-password -u elastic

把证书http_ca.crt从容器复制一份到宿主机,保存在当前目录,路径为"./http_ca.crt"

docker cp es01:/usr/share/elasticsearch/config/certs/http_ca.crt .

运行命令查看restful api是否运行正常

curl --cacert http_ca.crt -u elastic:$ELASTIC_PASSWORD "https://localhost:9200"

如果收到如下输出,说明ES运行正常

{
  "name" : "xxxf4ac4xxx",
  "cluster_name" : "docker-cluster",
  "cluster_uuid" : "xxxx1x9j3qQ_xxx",
  "version" : {
    "number" : "9.1.0",
    "build_flavor" : "default",
    "build_type" : "docker",
    "build_hash" : "dasdfa1a2f57de895a73a1391ff8426c0153c8d",
    "build_date" : "2025-05-24T22:05:04.526302670Z",
    "build_snapshot" : false,
    "lucene_version" : "10.2.2",
    "minimum_wire_compatibility_version" : "8.19.0",
    "minimum_index_compatibility_version" : "8.0.0"
  },
  "tagline" : "You Know, for Search"
}

2 python连接

pip安装elasticsearch包

pip install elasticsearch

python访问ES代码如下所示,证书文件“./http_ca.crt'”在当前目录。

from elasticsearch import Elasticsearch
import ssl
import asynciossl_context = ssl.create_default_context(cafile='./http_ca.crt')
es = Elasticsearch(['https://localhost:9200'],http_auth=('elastic', 'passwd‘),# scheme="https",ssl_context=ssl_context
)def main():info = es.info()print(info)# 运行主函数
main()

输出如下,说明ES运行正常。

{'name': 'c2542f4ac460', xxxx 'tagline': 'You Know, for Search'}

3 建立索引

建立search-ahz2索引,包含两个字段: vector,text,代码如下。

from elasticsearch import Elasticsearchclient = Elasticsearch(['https://localhost:9200'],http_auth=('elastic', 'passwd'),# scheme="https",ssl_context=ssl_context
)index_name = "search-ahz2"mappings = {"properties": {"vector": {"type": "dense_vector","dims": 3},"text": {"type": "text"}}
}mapping_response = client.indices.put_mapping(index=index_name, body=mappings)
print(mapping_response)

输出如下,说明索引正确建立

{'acknowledged': True}

4 数据导入

数据导入代码如下所示

from elasticsearch import Elasticsearch, helpersclient = Elasticsearch(['https://localhost:9200'],http_auth=('elastic', 'passwd'),ssl_context=ssl_context
)index_name = "search-ahz2"docs = [{"text": "Yellowstone National Park is one of the largest national parks in the United States. It ranges from the Wyoming to Montana and Idaho, and contains an area of 2,219,791 acress across three different states. Its most famous for hosting the geyser Old Faithful and is centered on the Yellowstone Caldera, the largest super volcano on the American continent. Yellowstone is host to hundreds of species of animal, many of which are endangered or threatened. Most notably, it contains free-ranging herds of bison and elk, alongside bears, cougars and wolves. The national park receives over 4.5 million visitors annually and is a UNESCO World Heritage Site.","vector": [4.667,0.145,3.07]},{"text": "Yosemite National Park is a United States National Park, covering over 750,000 acres of land in California. A UNESCO World Heritage Site, the park is best known for its granite cliffs, waterfalls and giant sequoia trees. Yosemite hosts over four million visitors in most years, with a peak of five million visitors in 2016. The park is home to a diverse range of wildlife, including mule deer, black bears, and the endangered Sierra Nevada bighorn sheep. The park has 1,200 square miles of wilderness, and is a popular destination for rock climbers, with over 3,000 feet of vertical granite to climb. Its most famous and cliff is the El Capitan, a 3,000 feet monolith along its tallest face.","vector": [4.222,3.251,6.634]},{"text": "Rocky Mountain National Park  is one of the most popular national parks in the United States. It receives over 4.5 million visitors annually, and is known for its mountainous terrain, including Longs Peak, which is the highest peak in the park. The park is home to a variety of wildlife, including elk, mule deer, moose, and bighorn sheep. The park is also home to a variety of ecosystems, including montane, subalpine, and alpine tundra. The park is a popular destination for hiking, camping, and wildlife viewing, and is a UNESCO World Heritage Site.","vector": [6.504,9.081,0.003]}
]
bulk_response = helpers.bulk(client, docs, index=index_name)
print(bulk_response)

5 数据查询

基于向量"query_vector": [-5, 9, -12],采用最近邻knn方式查询,代码示例如下。

from elasticsearch import Elasticsearchssl_context = ssl.create_default_context(cafile='./http_ca.crt')client = Elasticsearch(['https://localhost:9200'],http_auth=('elastic', 'A2x92P-rsDoCxyTuFet='),ssl_context=ssl_context
)retriever_object = {"standard": {"query": {"knn": {"field": "vector","query_vector": [-5, 9, -12],"num_candidates": 100,"k": 1}}}
}search_response = client.search(index="search-ahz2",retriever=retriever_object,
)
print(search_response['hits']['hits'])

结果如下所示。

[{'_index': 'search-ahz2', '_id': '1hF_OJkBGOYBI6JUku22', '_score': 0.7304765, '_source': {'text': 'Rocky Mountain National Park  is one of the most popular national parks in the United States. It receives over 4.5 million visitors annually, and is known for its mountainous terrain, including Longs Peak, which is the highest peak in the park. The park is home to a variety of wildlife, including elk, mule deer, moose, and bighorn sheep. The park is also home to a variety of ecosystems, including montane, subalpine, and alpine tundra. The park is a popular destination for hiking, camping, and wildlife viewing, and is a UNESCO World Heritage Site.', 'vector': [6.504, 9.081, 0.003]}}]

reference

---

docker搭建elasticsearch并使用python连接

https://zhuanlan.zhihu.com/p/660380507

详细教程:如何使用elasticsearch 8.x进行向量搜索

https://blog.csdn.net/qq_50790981/article/details/140336167

kNN 搜索

https://elastic.ac.cn/docs/solutions/search/vector/knn

http://www.dtcms.com/a/595407.html

相关文章:

  • 网站单页制作教程seo基础知识培训视频
  • 大连网站制作诚推ls15227网站建设企业模板
  • 上海专业做网站推广的公司金融理财管理网站源码 dedecms
  • 德国域名申请网站建设银行官网学生交费网站
  • 如何自己创造网站justnews wordpress
  • wordpress查询标签seo运营招聘
  • 网站开发中的网页上传和网站发布电池外贸一般在哪些网站做
  • 什么样的企业需要做网站国家网站icp备案查询
  • 东莞樟木头网站建设公司四川建设网证书查询平台官网
  • 建设企业网站的保险网
  • 营销型网站策划 ppt110平方装修全包价格
  • 网站建设价格标准信息中小企业商务网站建设
  • 地图网站怎么做网站备案密码使用
  • 南通医院网站建设方案最新远程网站建设服务
  • 怎么做企业网站优化需要多少钱前端自己做博客网站
  • 幻灯网站源码网站开发备案认证
  • 专业的网站制作公司地址德兴网站seo
  • 十大高端网站定制设计师查企业免费查询
  • 高端网站建设 司法高端网站源码
  • 唐山建设个网站不能用于制作网页的软件
  • 动易 手机网站建设部政务网站建设
  • 国外网站打开很慢100个成功营销案例
  • 红色扁平化网站网站推广计划机构
  • 电子商务实网站的建设课件百度一下首页百度
  • 南京企业网站设计制作去哪里找需要推广的app
  • jsp做的网站源码佛山网站设计联系方式
  • 代做论文的网站有哪些好的WordPress 图标字体
  • linux怎么做网站宣传渠道有哪些
  • 优化排名推广教程网站地域名网址查询
  • 做外贸网站需要注意些什么手续网站的标题符号