Skip to content

当有新的 Blog 被保存时会触发 signals,在 ElasticSearch 中也生成一份并重建索引,最终在 Django 中实现高速查询

License

Notifications You must be signed in to change notification settings

tmpbook/Django-with-ElasticSearch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Django-with-ElasticSearch

当有新的 blog 被保存时触发一个 signals,在 ElasticSearch 中也生成一份并重建索引,最终在 Django 中实现高速查询 API: search

安装 ElasticSearch

mkdir elasticsearch-example
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.1.1.tar.gz
tar -xzf elasticsearch-5.1.1.tar.gz
./elasticsearch-5.1.1/bin/elasticsearch

安装运行 Django 项目

git clone https://github.com/tmpbook/Django-with-ElasticSearch.git
cd Django-with-ElasticSearch/elasticsearchproject

# 安装所需要的包
pip3 install -r requirements.txt

python manage.py runserver
# Starting development server at http://127.0.0.1:8000/

# 然后访问在这个 endpoint 添加一个 blog 对象
open http://127.0.0.1:8000/admin/elasticsearchapp/blogpost/add/

查看 ElasticSearch 并验证

curl -XGET 'localhost:9200/blogpost-index/blog_post_index/1?pretty'

# 应该是这样
{
  "_index" : "blogpost-index",
  "_type" : "blog_post_index",
  "_id" : "1",
  "_version" : 2,
  "found" : true,
  "_source" : {
    "author" : "admin",
    "posted_date" : "2017-12-21",
    "text" : "Blog content.",
    "title" : "blog title"
  }
}

About me

知乎:临书

微信(WeChat):

谢谢阅读
Thanks for watching

About

当有新的 Blog 被保存时会触发 signals,在 ElasticSearch 中也生成一份并重建索引,最终在 Django 中实现高速查询

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy