# البحث النصي الكامل (Pt 2 - مقدمة على OpenSearch)

<!--category-- OpenSearch -->
<datetime class="hidden">2024-08-24T03:00</datetime>

## المقدمة

في الأجزاء السابقة من هذا السلسلة قدمنا مفهوم البحث النصي الكامل وكيف يمكن استخدامه لبحث عن النص في قاعدة بيانات. في هذا الجزء سنقوم بعرض OpenSearch, محرك بحث قوي يمكن استخدامها لبحث عنه

في هذا الجزء سنقوم بشرح كيفية الحصول على OpenSearch وتشغيله

أجزاء سابقة في هذه السلسلة:

- [البحث النصي الكامل مع Postgres](/blog/textsearchingpt1)
- [صندوق البحث مع Postgres](/blog/textsearchingpt11)

الأجزاء التالية في هذه السلسلة:

- [البحث المفتوح مع C#](/blog/textsearchingpt3)

[TOC]

## ما هو OpenSearch?

[البحث المفتوح](https://opensearch.org/) هو محرك بحث مصمم ليكون سريعاً , قابل للانحدار وسهل الاستخدام . إنه فرع من Elasticsearch MSC2 محرك البحث الشائع الذي يستخدمه العديد من الشركات لتشغيل وظائفهم البحثية MSC3 OpenSearch مصمم لتكون سهلة الاستخدام ويمكن استخدامها لبحث عن النص بطرق مختلفة مختلفة

على الرغم من أن "مسك0" ليس حيواناً بسيطاً للذهاب والاستعمال، لذا سنقوم بتغطية الأساسيات في هذا المقال "مسک1"

![البحث المفتوح](opensearch.webp?width=900&quality=25)

## Installing OpenSearch

أولاً , هذا ليس ' لا يجب أن تستخدمه في الإنتاج | ; | إنه يضع عدداً من مستخدمي العرض و كلمات المرور غير آمنة . [الوثائق الرسمية](https://opensearch.org/docs/) لإعداد مجموعة آمنة.

أولا , نحن نستخدم تلقائيا 'Development' install the docker of Opensearch | & | Opensearch Dashboards |( | think | , | UI to manage the cluster

شاهدوا هنا كل التفاصيل على [إعداد "دوكر كومبيج"](https://opensearch.org/docs/latest/install-and-configure/install-opensearch/docker/).

أنت' ستحتاج إلى تعديل صغير على أي Wsl / مضيف اللينكس الخاص بك لجعله يعمل بسلاسة
إعدادات للينكس
في بيئة للينكس, تقوم بتشغيل الأوامر التالية:

من شأنه أن يحوّل فعالية الاتصال بالذاكرة والتبادل على المضيف لتحسين الأداء.

```bash
sudo swapoff -a
```

زيادة عدد خرائط الذاكرة المتاحة لOpenSearch.

```bash

# Edit the sysctl config file
sudo vi /etc/sysctl.conf

# Add a line to define the desired value
# or change the value if the key exists,
# and then save your changes.
vm.max_map_count=262144

# Reload the kernel parameters using sysctl
sudo sysctl -p

# Verify that the change was applied by checking the value
cat /proc/sys/vm/max_map_count

```

إعداد الحواسيب
بالنسبة للحواسيب وينډوز التي تستخدم WSL من خلال ផ្ទៃតុ دونكر, تقوم بتشغيل الأوامر التالية في محطة لتحديد vm.maxM SK2map _countMSC4

```bash
wsl -d docker-desktop
sysctl -w vm.max_map_count=262144
```

ثم يمكنك إنشاء `.env` في نفس المجلد `docker-compose.yml` File with the following content:
`bash OPENSEARCH_INITIAL_ADMIN_PASSWORD=<somepasswordwithlowercaseuppercaseandspecialchars> `

الآن يمكنك استخدام الدوكر التالي- compose file لإعداد Cluster:

```yaml
version: '3'
services:
  opensearch-node1: # This is also the hostname of the container within the Docker network (i.e. https://opensearch-node1/)
    image: opensearchproject/opensearch:latest # Specifying the latest available image - modify if you want a specific version
    container_name: opensearch-node1
    environment:
      - cluster.name=opensearch-cluster # Name the cluster
      - node.name=opensearch-node1 # Name the node that will run in this container
      - discovery.seed_hosts=opensearch-node1,opensearch-node2 # Nodes to look for when discovering the cluster
      - cluster.initial_cluster_manager_nodes=opensearch-node1,opensearch-node2 # Nodes eligible to serve as cluster manager
      - bootstrap.memory_lock=true # Disable JVM heap memory swapping
      - "OPENSEARCH_JAVA_OPTS=-Xms512m -Xmx512m" # Set min and max JVM heap sizes to at least 50% of system RAM
      - OPENSEARCH_INITIAL_ADMIN_PASSWORD=${OPENSEARCH_INITIAL_ADMIN_PASSWORD}    # Sets the demo admin user password when using demo configuration, required for OpenSearch 2.12 and later
    ulimits:
      memlock:
        soft: -1 # Set memlock to unlimited (no soft or hard limit)
        hard: -1
      nofile:
        soft: 65536 # Maximum number of open files for the opensearch user - set to at least 65536
        hard: 65536
    volumes:
      - opensearch-data1:/usr/share/opensearch/data # Creates volume called opensearch-data1 and mounts it to the container
    ports:
      - 9200:9200 # REST API
      - 9600:9600 # Performance Analyzer
    networks:
      - opensearch-net # All of the containers will join the same Docker bridge network
  opensearch-node2:
    image: opensearchproject/opensearch:latest # This should be the same image used for opensearch-node1 to avoid issues
    container_name: opensearch-node2
    environment:
      - cluster.name=opensearch-cluster
      - node.name=opensearch-node2
      - discovery.seed_hosts=opensearch-node1,opensearch-node2
      - cluster.initial_cluster_manager_nodes=opensearch-node1,opensearch-node2
      - bootstrap.memory_lock=true
      - "OPENSEARCH_JAVA_OPTS=-Xms512m -Xmx512m"
      - OPENSEARCH_INITIAL_ADMIN_PASSWORD=${OPENSEARCH_INITIAL_ADMIN_PASSWORD}
    ulimits:
      memlock:
        soft: -1
        hard: -1
      nofile:
        soft: 65536
        hard: 65536
    volumes:
      - opensearch-data2:/usr/share/opensearch/data
    networks:
      - opensearch-net
  opensearch-dashboards:
    image: opensearchproject/opensearch-dashboards:latest # Make sure the version of opensearch-dashboards matches the version of opensearch installed on other nodes
    container_name: opensearch-dashboards
    ports:
      - 5601:5601 # Map host port 5601 to container port 5601
    expose:
      - "5601" # Expose port 5601 for web access to OpenSearch Dashboards
    environment:
      OPENSEARCH_HOSTS: '["https://opensearch-node1:9200","https://opensearch-node2:9200"]' # Define the OpenSearch nodes that OpenSearch Dashboards will query
    networks:
      - opensearch-net

volumes:
  opensearch-data1:
  opensearch-data2:

networks:
  opensearch-net:
```

هذا الدوكر - سوف ينشئ مجموعة من العقد 2 من Opensearch وعقد واحد من لوحات البحث المفتوحة

إنها تعتمد على ឯកសារ .env الخاصة بك لتحديد `OPENSEARCH_INITIAL_ADMIN_PASSWORD` المتغير.

ثم قم بتحريكها

```bash
docker compose -f opensearch-docker.yml up -d
```

في المستقبل سوف نذهب إلى أعمق حول ما يفعله هذا وكيفية إعداده للتصنيع

### الوصول إلى "OpenSearch"

بمجرد أن تقوم بتركيب المجمع وتشغيله, يمكنك الوصول لواجهة لوحات البحث المفتوحة عن طريق التصفح إلى `http://localhost:5601` في متصفحك الويب. يمكنك الدخول باستخدام username `admin` وكلمة المرور التي وضعتها في `.env` فايل.

![لوحات البحث المفتوحة](opensearchdashboards.png?width=600&format=webp&quality=25)

هذا هو واجهة admin الرئيسية لك ( يمكنك أن تشغله ببعض بيانات العينات وتلعب معه

![لوحات البحث المفتوحة](dashboard.png?width=600&format=webp&quality=25)

## في الختام

في الجزء التالي سأقوم بشرح كيفية الحصول على البيانات في البحث المفتوح وبحث عنها