PHPackages                             xudongyss/es - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. xudongyss/es

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

xudongyss/es
============

0.1.1(1y ago)012PHP

Since Nov 28Pushed 1y ago1 watchersCompare

[ Source](https://github.com/xudongyss/es)[ Packagist](https://packagist.org/packages/xudongyss/es)[ RSS](/packages/xudongyss-es/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (2)Versions (12)Used By (0)

快速开始
====

[](#快速开始)

配置
--

[](#配置)

项目入口文件

```
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
$dotenv->load();
```

配置文件 .env 放在项目入口文件同级目录

```
ELASTICSEARCH_HOST=""
ELASTICSEARCH_USERNAME=""
ELASTICSEARCH_PASSWORD=""
```

创建索引
----

[](#创建索引)

```
use xudongyss\es\Client;
use xudongyss\es\index\Index;
use xudongyss\es\index\Analyzer;
use xudongyss\es\index\mappings\properties\Field;

$index = Index::create()
    ->setIndex('jxzrzyhgh')
    ->setSettingsNumberOfShards(3)
    ->setSettingsNumberOfReplicas(2)
    ->setSettingsAnalysisAnalyzer(Analyzer::create()
        ->setName('ik_analyzer')
        ->setType('custom')
        ->setTokenizer('ik_max_word'))
    ->setMappingsProperties(Field::create()
        ->setFiled('id')
        ->setType('integer'))
    ->setMappingsProperties(Field::create()
        ->setFiled('title')
        ->setType('text')
        ->setAnalyzer('ik_analyzer')
        ->setFields(Field::create()
            ->setFiled('raw')
            ->setType('keyword')
        )
    )
    ->setMappingsProperties(Field::create()
        ->setFiled('content')
        ->setType('text')
        ->setAnalyzer('ik_analyzer')
    )
    ->setMappingsProperties(Field::create()
        ->setFiled('url')
        ->setType('keyword')
    )
    ->setMappingsProperties(Field::create()
        ->setFiled('create_time')
        ->setType('date')
        ->setFormat('yyyy-MM-dd HH:mm:ss')
    )
    ->build();
Client::indices()->create($index);
```

### Geopoint field type

[](#geopoint-field-type)

```
use xudongyss\es\Client;
use xudongyss\es\index\Index;
use xudongyss\es\index\mappings\properties\Field;

$index = Index::create()
    ->setIndex('geo')
    ->setSettingsNumberOfShards(3)
    ->setSettingsNumberOfReplicas(2)
    ->setMappingsProperties(Field::create()
        ->setFiled('name')
        ->setType('keyword')
    )
    ->setMappingsProperties(Field::create()
        ->setFiled('location')
        ->setType('geo_point')
    )
    ->build();
Client::indices()->create($index);
```

插入
--

[](#插入)

```
use xudongyss\es\Client;
use xudongyss\es\document\Index;

$params = Index::create()
    ->setIndex('jxzrzyhgh')
    ->setId('')
    ->setBody([
        'id' => '',
        'title' => '',
        'content' => '',
        'url' => '',
        'create_time' => ''
    ])
    ->build();
Client::index($params);
```

### Geopoint field type

[](#geopoint-field-type-1)

```
// lat: 纬度，lon: 经度
$params = DocumentIndex::create()
    ->setIndex('geo')
    ->setBody([
        'name' => '正荣光谷紫阙台',
        'location' => '30.479665,114.39972',    // lat,lon
    ])
    ->build();

$params = DocumentIndex::create()
    ->setIndex('geo')
    ->setBody([
        'name' => '正荣光谷紫阙台',
        'location' => [114.39972, 30.479665],    // [lon, lat]
    ])
    ->build();

$params = DocumentIndex::create()
    ->setIndex('geo')
    ->setBody([
        'name' => '正荣光谷紫阙台',
        'location' => [
            'lat' => 30.503151,
            'lon' => 114.414082,
        ]
    ])
    ->build();
```

搜索
--

[](#搜索)

### query And bool

[](#query-and-bool)

#### match

[](#match)

```
use xudongyss\es\document\highlight\Field;
use xudongyss\es\document\query\QueryMatch;
use xudongyss\es\document\Search;

$params = Search::create()
    ->setIndex('jxzrzyhgh')
    ->setQueryBoolShould(QueryMatch::create()
        ->setQuery('武汉')
        ->setField('title'))
    ->setSourceIncludes(['id', 'title', 'url', 'create_time'])
    ->setHighlightFields(Field::create()
        ->setField('title'))
    ->setSize(10000)
    ->build();
$list = Client::search($params);
$list = json_decode((string)$list->getBody(), true);
```

#### match\_phrase

[](#match_phrase)

```
use xudongyss\es\document\highlight\Field;
use xudongyss\es\document\query\MatchPhrase;
use xudongyss\es\document\Search;

$params = Search::create()
    ->setIndex('jxzrzyhgh')
    ->setQueryBoolShould(MatchPhrase::create()
        ->setQuery('武汉')
        ->setField('title'))
    ->setSourceIncludes(['id', 'title', 'url', 'create_time'])
    ->setHighlightFields(Field::create()
        ->setField('title'))
    ->setSize(10000)
    ->build();
$list = Client::search($params);
$list = json_decode((string)$list->getBody(), true);
```

#### multi\_match

[](#multi_match)

```
use xudongyss\es\document\highlight\Field;
use xudongyss\es\document\query\MultiMatch;
use xudongyss\es\document\Search;

$params = Search::create()
    ->setIndex('jxzrzyhgh')
    ->setQueryBoolShould(MultiMatch::create()
        ->setQuery('武汉')
        ->setFields(['title'])
    )
    ->setSourceIncludes(['id', 'title', 'url', 'create_time'])
    ->setHighlightFields(Field::create()
        ->setField('title'))
    ->setSize(10000)
    ->build();

// phrase
$params = Search::create()
    ->setIndex('jxzrzyhgh')
    ->setQueryBoolShould(MultiMatch::create()
        ->setQuery('武汉')
        ->setFields(['title'])
        ->setType('phrase')
    )
    ->setSourceIncludes(['id', 'title', 'url', 'create_time'])
    ->setHighlightFields(Field::create()
        ->setField('title'))
    ->setSize(10000)
    ->build();

$list = Client::search($params);
$list = json_decode((string)$list->getBody(), true);
```

#### term

[](#term)

```
use xudongyss\es\document\highlight\Field;
use xudongyss\es\document\query\Term;
use xudongyss\es\document\Search;

$params = Search::create()
    ->setIndex('jxzrzyhgh')
    ->setQueryBoolShould(Term::create()
        ->setField('url')
        ->setValue('https://baidu.com')
    )
    ->setSourceIncludes(['id', 'title', 'url', 'create_time'])
    ->setHighlightFields(Field::create()
        ->setField('title'))
    ->setSize(10000)
    ->build();

$list = Client::search($params);
$list = json_decode((string)$list->getBody(), true);
```

#### terms

[](#terms)

```
use xudongyss\es\document\highlight\Field;
use xudongyss\es\document\query\Terms;
use xudongyss\es\document\Search;

$params = Search::create()
    ->setIndex('jxzrzyhgh')
    ->setQueryBoolShould(Terms::create()
        ->setField('url')
        ->setTerms(['https://baidu.com'])
    )
    ->setSourceIncludes(['id', 'title', 'url', 'create_time'])
    ->setHighlightFields(Field::create()
        ->setField('title'))
    ->setSize(10000)
    ->build();

$list = Client::search($params);
$list = json_decode((string)$list->getBody(), true);
```

#### range

[](#range)

```
use xudongyss\es\document\highlight\Field;
use xudongyss\es\document\query\Range;
use xudongyss\es\document\Search;

$params = Search::create()
    ->setIndex('jxzrzyhgh')
    ->setQueryBoolShould(Range::create()
        ->setField('create_time')
        ->setGte(date('Y-m-d H:i:s', strtotime('-7 days')))
        ->setLte(date('Y-m-d H:i:s'))
    )
    ->setSourceIncludes(['id', 'title', 'url', 'create_time'])
    ->setHighlightFields(Field::create()
        ->setField('title'))
    ->setSize(10000)
    ->build();

$list = Client::search($params);
$list = json_decode((string)$list->getBody(), true);
```

#### ids

[](#ids)

```
use xudongyss\es\document\highlight\Field;
use xudongyss\es\document\query\IDs;
use xudongyss\es\document\Search;

$params = Search::create()
    ->setIndex('jxzrzyhgh')
    ->setQuery(IDs::create()
        ->setValues([34709, 36923, 42330])
    )
    ->setSourceIncludes(['id', 'title', 'url', 'create_time'])
    ->setHighlightFields(Field::create()
        ->setField('title'))
    ->setSize(10000)
    ->build();

$list = Client::search($params);
$list = json_decode((string)$list->getBody(), true);
```

#### geo\_distance

[](#geo_distance)

```
use xudongyss\es\document\query\geo\Distance;
use xudongyss\es\document\Search;

$params = Search::create()
    ->setIndex('geo')
    ->setQuery(Distance::create()
        ->setField('location')
        ->setDistance('5km')
        ->setLocation('30.503151,114.414082')
    )
    ->setFields(['name', 'location'])
    ->build();
```

### query

[](#query)

### bool

[](#bool)

### script\_fields

[](#script_fields)

```
use xudongyss\es\document\query\geo\Distance;
use xudongyss\es\document\script\Field;
use xudongyss\es\document\Search;

$params = Search::create()
    ->setIndex('geo')
    ->setQuery(Distance::create()
        ->setField('location')
        ->setDistance('5km')
        ->setLocation('30.503151,114.414082')
    )
    ->setFields(['name', 'location'])
    ->setScriptFields(Field::create()
        ->setField('distance_to_target')
        ->setSource("doc['location'].arcDistance(params.lat, params.lon)")
        ->setParams('lat', 30.503151)
        ->setParams('lon', 114.414082)
    )
    ->build();
```

### fields

[](#fields)

### source

[](#source)

### from

[](#from)

```
use xudongyss\es\document\highlight\Field;
use xudongyss\es\document\query\QueryMatch;
use xudongyss\es\document\Search;

$params = Search::create()
    ->setIndex('jxzrzyhgh')
    ->setQueryBoolShould(QueryMatch::create()
        ->setQuery('武汉')
        ->setField('title'))
    ->setSourceIncludes(['id', 'title', 'url', 'create_time'])
    ->setHighlightFields(Field::create()
        ->setField('title'))
    ->setFrom(0)
    ->setSize(5)
    ->build();
$list = Client::search($params);
$list = json_decode((string)$list->getBody(), true);
```

### size

[](#size)

### sort

[](#sort)

```
use xudongyss\es\document\highlight\Field;
use xudongyss\es\document\query\QueryMatch;
use xudongyss\es\document\Search;
use xudongyss\es\document\Sort;

$params = Search::create()
    ->setIndex('jxzrzyhgh')
    ->setQueryBoolShould(QueryMatch::create()
        ->setQuery('武汉')
        ->setField('title'))
    ->setSourceIncludes(['id', 'title', 'url', 'create_time'])
    ->setHighlightFields(Field::create()
        ->setField('title'))
    ->setFrom(0)
    ->setSize(5)
    ->setSort(Sort::create()
        ->setField('create_time')
        ->setOrder('desc')
    )
    ->build();
```

### highlight

[](#highlight)

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance39

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity35

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

11

Last Release

521d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0f89328b21f1a0ff093d7c8df84f784af3cdd9c81c016362a65eb98dac4634fe?d=identicon)[xudongyss](/maintainers/xudongyss)

---

Top Contributors

[![xudongyss](https://avatars.githubusercontent.com/u/44386082?v=4)](https://github.com/xudongyss "xudongyss (46 commits)")

### Embed Badge

![Health badge](/badges/xudongyss-es/health.svg)

```
[![Health](https://phpackages.com/badges/xudongyss-es/health.svg)](https://phpackages.com/packages/xudongyss-es)
```

###  Alternatives

[roots/bedrock

WordPress boilerplate with Composer, easier configuration, and an improved folder structure

6.5k441.8k2](/packages/roots-bedrock)[akaunting/laravel-money

Currency formatting and conversion package for Laravel

7825.3M18](/packages/akaunting-laravel-money)[cognesy/instructor-php

The complete AI toolkit for PHP: unified LLM API, structured outputs, agents, and coding agent control

310107.9k1](/packages/cognesy-instructor-php)[blair2004/nexopos

The Free Modern Point Of Sale System build with Laravel, TailwindCSS and Vue.js.

1.2k2.3k](/packages/blair2004-nexopos)[lullabot/drainpipe

An automated build tool to allow projects to have a set standardized operations scripts.

41716.4k2](/packages/lullabot-drainpipe)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

255.2k](/packages/aedart-athenaeum)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
