Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
自定义分析器不支持';搜索弹性搜索时不工作 - Fatal编程技术网

自定义分析器不支持';搜索弹性搜索时不工作

自定义分析器不支持';搜索弹性搜索时不工作,
Warning: implode(): Invalid arguments passed in /data/phpspider/zhask/webroot/tpl/detail.html on line 45
,,我创建文档索引,类型为\u doc。然后我 设置自定义分析器如下 POST /documents/_close PUT /documents/_settings { "settings": { "analysis": { "analyzer": { "custom_analyzer": { &quo

我创建
文档
索引,类型为
\u doc
。然后我 设置自定义分析器如下

POST /documents/_close
PUT /documents/_settings
{
    "settings": {
        "analysis": {
            "analyzer": {
                "custom_analyzer": {
                    "type": "custom",
                    "tokenizer": "standard",
                    "filter": [
                        "lowercase",
                        "word_delimiter_graph"
                    ]
                }
            }
        }
    },
    "mappings": {
        "properties": {
            "question": {
                "type": "text",
                "analyzer": "custom_analyzer"
            },
            "question_group": {
                "type": "text",
                "analyzer": "custom_analyzer"
            }
        }
    }
}
POST /documents/_open
我尝试使用这个
定制的\u分析器
,然后它就可以工作了

POST http://localhost:9200/documents/_analyze
{
  "analyzer": "custom_analyzer",
  "text": "FIRE_DETECTED"
}
# And the result (lowercase and remove _ )
{
    "tokens": [
        {
            "token": "fire",
            "start_offset": 0,
            "end_offset": 4,
            "type": "<ALPHANUM>",
            "position": 0
        },
        {
            "token": "detected",
            "start_offset": 5,
            "end_offset": 13,
            "type": "<ALPHANUM>",
            "position": 1
        }
    ]
}

解决方案

尝试使用新设置创建新索引(如上)

索引数据

PUT http://localhost:9200/documents5/_doc/1
{
  "question": "fire_detected"
}

搜索

这是因为您刚刚将
自定义\u分析器的定义添加到索引中,但没有对数据(索引中的文档)重新编制索引,因此反向索引中不存在新标记要解决此问题,只需重新编制搜索结果中所需文档的索引。

您正在使用
multi_match
查询,该查询在内部使用
match
查询,这些查询经过分析,因此不需要搜索时间分析器

match
查询使用在字段上定义的同一分析器创建搜索标记(即从搜索词创建)

返回与提供的文本、数字、日期或布尔值匹配的文档 价值观匹配前分析提供的文本。


1.我创建了一个新索引
new\u documents
2。然后,我将客户分析器设置为
新文档
索引3。我重新索引
文档
索引到
新文档
4。我试过POST
/\u analyze
,它可以工作5。但是当我尝试搜索时,它仍然没有找到任何东西…@TranDinhHuy奇怪,我只是尝试了你的样本数据,它对我有效,你能显示你的索引请求吗,确保你在你的
问题
问题组
字段中对数据进行了索引请查看我编辑的帖子。从“尝试创建一个新索引”开始@TranDinhHuy很有趣,但有一件事我不明白你为什么要关闭和打开一个索引,在新索引上,你可以简单地指定这个分析器并索引文档,我希望你在设置这个分析器之后索引文档,如果我同时使用新设置创建一个新索引。它起作用了。
PUT /documents5
{
    "settings": {...}
}
PUT http://localhost:9200/documents5/_doc/1
{
  "question": "fire_detected"
}