Rückübersetzt als: „PHP-Syntax ElasticSearch'
P粉176203781
P粉176203781 2023-08-28 15:43:18
0
1
536
<p>我是ElasticSearch的新手,对查询的工作原理不太了解... 我的索引示例</p> <pre class="brush:php;toolbar:false;">{ "_index" : "indexing001", "_type" : "_doc", "_id" : "3", "_version" : 1, "_seq_no" : 242, "_primary_term" : 2, "gefunden" : WAHR, "_source" : { "Typ" : 1, "sub_type" : Null, "Benutzer" : { "id" : 1, "Name" : "tk6z2 gcnouvqmr" }, "editor_user" : [ ], "Inhalt" : [ { "Titel" : "Titel #3", "short_text" : "Artikel #3 Kurztext", "Volltext" : "Artikel #3 Volltext", "Gebietsschema" : "de-DE" } ], "Flaggen" : [ ], "Standort" : [ ], "Startdatum" : 1658793600, "end_date" : 1658793600, "_users" : [ ] } }</pre> <p>我想查询文本以匹配字段<code>content.title</code> und <code>content.short_text</code> Nein.例如,我的函数是:</p> <pre class="brush:php;toolbar:false;">öffentliche statische Funktionssuche( string $text = '', int $user = 0 ): Array { versuchen { $model = new someModelClass(); $fields = [ 'content.title', 'content.short_text', ]; $result = $model::find()->query( [ 'bool' => [ 'sollte' => [ 'multi_match' => [ 'query' => $text, 'Felder' => $fields, ], ], 'filter' => [ [ 'Begriff' => [ '_users.id' => $user ] ], [ 'Begriff' => [ '_users' => [] ] ], ] ], ] )->all(); $result zurückgeben; } Catch (Ausnahme $e) { throw new Exception( $e->getMessage() ); } }</pre> <p>将其转换为SQL应该是这样的:<code>SELECT * FROM 'indexing001' WHERE (content.title LIKE %search% OR content.short_text LIKE %search%) AND (users.id = 1 OR Benutzer = '')</code> Was ist ElasticSearch? 提前感谢!</p>
P粉176203781
P粉176203781

Antworte allen(1)
P粉421119778

在这种情况下,我建议使用Elasticsearch-PHP客户端。

请使用composer 安装适当的客户端。

对于如下的匹配查询

curl -XGET 'localhost:9200/my_index/_search' -d '{
    "query" : {
        "match" : {
            "testField" : "abc"
        }
    }
}'

您可以在您的PHP脚本中进行查询,如下所示

$params = [
    'index' => 'my_index',
    'body'  => [
        'query' => [
            'match' => [
                'testField' => 'abc'
            ]
        ]
    ]
];

$results = $client->search($params);

这里查看更多操作。

Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage