English | 中文
A demo of elasticsearch in python.
Implement additions, deletions, changes, and queries, as well as batch storage, match, multi_match and compound queries, and helpers scan query methods.
For more details on elasticsearch search query methods, please check https://blog.csdn.net/Thanours/article/details/109625553
1.Install elasticsearch
The installation and startup of elasticsearch in ubuntu and docker is very simple.
https://blog.csdn.net/Thanours/article/details/109592219
You can also go to the official website to refer to the installation tutorial: https://www.elastic.co/guide/en/elasticsearch/reference/current/install-elasticsearch.html
2.python:
python3.6
pip install elasticsearch==7.9.1
- Implement the encapsulation python class of elasticsearch, including addition, deletion, modification, query, batch storage, and helpers scan query methods.
- The Elasticsearch mappings configuration uses the ik tokenizer for Chinese. For how to configure the ik tokenizer in elasticsearch, please refer to: https://blog.csdn.net/Thanours/article/details/109619013
- Elasticsearch mappings configure query to use BM25 score
- Wikipedia data is stored in elasticsearch, and a variety of queries are implemented, including match and multi_match, and compound queries.
- You can use multiple keyword queries, or whole sentence questions to query. The number of returned results can be specified.
-
Complete the environment configuration in (1);
-
Download Wikipedia data:https://github.com/brightmart/nlp_chinese_corpus/;
-
Unzip the downloaded Wikipedia data and put it in the data folder;
-
Run python Retrieve.py, and the query results will be written to a file and saved to the data folder