php - Elasticsearch查找输入词和所有同义词

标签 php laravel elasticsearch

我尝试使用elasticsearch通过单词“skiing”找到所有项目。

我的映射(PHP数组):

"properties" => [
    "title" => [
        "type" => "string",
        "boost" => 1.0,
        "analyzer" => "autocomplete"
    ]
]

设定:
"settings"=> [
    "analysis" => [
        "analyzer" => [
            "autocomplete" => [
                "type" => "custom",
                "tokenizer" => "standard",
                "filter" => ["lowercase", "trim", "synonym", "porter_stem"],
                "char_filter" => ["html_strip"]
            ]
        ],
        "filter" => [
            "synonym" => [
                "type" => "synonym",
                "synonyms_path" => "analysis/synonyms.txt"
            ]
        ]
    ]
]

搜索查询:
[
    "index" => "articles",
    "body" =>  [
        "query" =>  [
            "filtered" =>  [
                "query" =>  [
                    "bool" =>  [
                        "must" =>  [
                            "indices" =>  [
                                "indices" =>  ["articles"],
                                "query" =>  [
                                    "bool" =>  [
                                        "should" =>  [
                                            "multi_match" =>  [
                                                "query" => "skiing",
                                                "fields" => ["title"]
                                            ]
                                        ]
                                    ]
                                ]
                            ]
                        ]
                    ]
                ]
            ]
        ],
        "sort" =>  [
            "_score" =>  [
                "order" => "desc"
            ]
        ]
    ],
    "size" => 10,
    "from" => 0,
    "search_type" => "dfs_query_then_fetch",
    "explain" => true
];

在sysnonyms.txt中,有skiing => xanthic。

我想获得所有带有“skiing”(因为它是输入词),“ski”(由porter_stem tokenizer生成)和“xanthic”(由同义词文件生成)的项目。但是仅用单词“xanthic”可获得结果。

请告诉我为什么?我该如何配置索引?

最佳答案

在同义词文件中,您需要有“xanthic滑雪”。用现在的方式,您正在用黄药代替滑雪,但您想同时保留两者。而且我认为您需要重新索引数据才能看到更改。

关于php - Elasticsearch查找输入词和所有同义词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39293985/

相关文章:

php - Laravel Scheduler 以 root 用户身份创建缓存文件

reactjs - 将 MediaRecorder 分块到 Google Cloud 平台时视频上传损坏

java - "match or null"在elasticsearch中查询

php - 通过 composer 从私有(private) Bitbucket 存储库导入包

javascript - 从 angularjs 获取图像名称并在 laravel Blade 中使用它?

php - Wordpress - 仅获取自定义分类/类别直接子项

php - Laravel Flash 或 session 消息不会过期 [未维护更新]

php - 无法打开流没有此类文件或目录

php - 预期[END_OBJECT],但获得了[FIELD_NAME]

elasticsearch - 无法将Marvel安装到Kibana中