簡體   English   中英

PHP Elasticsearch,帶有過濾器的布爾查詢未獲得任何結果

[英]PHP Elasticsearch, bool query with filter not getting any result

因此,我試圖在“名稱”字段中找到所有包含“ ssh”的文檔,其中“版本”字段等於12.1.2、12.1.1等。這是我的參數:

$params = [
            'index' => 'notes',
            'type' => 'release',
            'body' => [
            'query' => [
                'bool' => [
                        'must' => [
                            'match' => [ 'name' => 'ssh' ]
                            ],
                        'filter' => [
                            'term' => [ 'versions' => '12.1.2, 12.1.1, 12.1.0' ]
                            ]   
                        ]
                    ]
                ]
            ];

這是一個示例文件:

    Array
(
    [_index] => notes
    [_type] => release
    [_id] => AVo3jnT2RJ1Gn1RjrM7p
    [_score] => 0.52541894
    [_source] => Array
        (
            [name] => 621423 : sys-icheck reports error with /config/ssh/ssh_host_dsa_key
            [component] => TMOS
            [symptoms] => On Azure cloud, running sys-icheck may report an error with /config/ssh/ssh_host_dsa_key and other files:  ERROR: missing /config/ssh/ssh_host_dsa_key ERROR: missing /config/ssh/ssh_host_dsa_key.pub ERROR: missing /config/ssh/ssh_host_key ERROR: missing /config/ssh/ssh_host_key.pub
            [conditions] => This occurs on BIG-IP running on Azure cloud.
            [impact] => sys-icheck utility indicates an error. The sys-icheck utility is used to find file system changes that have occurred since initial installation and provide information about their status.
            [workaround] => 
            [fix] => Fixed an issue with files in /config/ssh/ that was causing sys-icheck to report errors.
            [versions] => 12.1.2, 12.1.1, 12.1.0
        )

)

根據要求,這是name映射:

{
    notes: {
        mappings: {
            release: {
                name: {
                    full_name: "name"
                    mapping: {
                        name: {
                            type: "text"
                            fields: {
                                keyword: {
                                    type: "keyword"
                                    ignore_above: 256
                                } -
                            } -
                        } -
                    } -
                } -
            } -
        } -
    } -
}

/ GET / notes的結果:

    {
    notes: {
        aliases: {}
        mappings: {
            release: {
                properties: {
                    component: {
                        type: "text"
                        fields: {
                            keyword: {
                                type: "keyword"
                                ignore_above: 256
                            } -
                        } -
                    } -
                    conditions: {
                        type: "text"
                        fields: {
                            keyword: {
                                type: "keyword"
                                ignore_above: 256
                            } -
                        } -
                    } -
                    fix: {
                        type: "text"
                        fields: {
                            keyword: {
                                type: "keyword"
                                ignore_above: 256
                            } -
                        } -
                    } -
                    impact: {
                        type: "text"
                        fields: {
                            keyword: {
                                type: "keyword"
                                ignore_above: 256
                            } -
                        } -
                    } -
                    name: {
                        type: "text"
                        fields: {
                            keyword: {
                                type: "keyword"
                                ignore_above: 256
                            } -
                        } -
                    } -
                    symptoms: {
                        type: "text"
                        fields: {
                            keyword: {
                                type: "keyword"
                                ignore_above: 256
                            } -
                        } -
                    } -
                    versions: {
                        type: "text"
                        fields: {
                            keyword: {
                                type: "keyword"
                                ignore_above: 256
                            } -
                        } -
                    } -
                    workaround: {
                        type: "text"
                        fields: {
                            keyword: {
                                type: "keyword"
                                ignore_above: 256
                            } -
                        } -
                    } -
                } -
            } -
        } -
        settings: {
            index: {
                creation_date: "1486999820715"
                number_of_shards: "5"
                number_of_replicas: "1"
                uuid: "SZfFCZ-HRT6Yr17epsv2-Q"
                version: {
                    created: "5020099"
                } -
                provided_name: "notes"
            } -
        } -
    } -
}

過濾器是唯一的工作語句,因為我已獲取所有12.1.2文檔。 有任何想法嗎?

這是因為字段name analyzer設置為keyword 當您這樣做時,它不會標記關鍵字。 因此,在這里您將必須使用全文搜索該文檔。

意思是如果您must在下面使用它,它將為您提供輸出。

621423 : sys-icheck reports error with /config/ssh/ssh_host_dsa_key

在此處查看keyword anlyzer

以下查詢對我有用,即您需要對versions使用terms查詢,並且每個版本都有一個數組。

 $params = [
        'index' => 'notes',
        'type' => 'release',
        'body' => [
        'query' => [
            'bool' => [
                    'must' => [
                        'match' => [ 'name' => 'ssh' ]
                    ],
                    'filter' => [
                        'terms' => [ 
                            'versions' => ['12.1.2', '12.1.1', '12.1.0']
                        ]   
                    ]
                ]
            ]
        ]
  ];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM