2017-04-05 55 views
0

我们正在运行Elasticsearch 1.7(计划很快升级),我试图使用Analyze API来了解不同分析器的功能,但弹性搜索的结果并不是我期望。分析API不适用于Elasticsearch 1.7

如果我跑反对我们elasticsearch例如

GET _analyze 
{ 
    "analyzer": "stop", 
    "text": "Extremely good food! We had the happiest waiter and the crowd's always flowing!" 
} 

下面的查询,我会得到这样的结果

{ 
    "tokens": [ 
    { 
    "token": "analyzer", 
    "start_offset": 6, 
    "end_offset": 14, 
    "type": "<ALPHANUM>", 
    "position": 1 
    }, 
    { 
    "token": "stop", 
    "start_offset": 18, 
    "end_offset": 22, 
    "type": "<ALPHANUM>", 
    "position": 2 
    }, 
    { 
    "token": "text", 
    "start_offset": 30, 
    "end_offset": 34, 
    "type": "<ALPHANUM>", 
    "position": 3 
    }, 
    { 
    "token": "extremely", 
    "start_offset": 38, 
    "end_offset": 47, 
    "type": "<ALPHANUM>", 
    "position": 4 
    }, 
    { 
    "token": "good", 
    "start_offset": 48, 
    "end_offset": 52, 
    "type": "<ALPHANUM>", 
    "position": 5 
    }, 
    { 
    "token": "food", 
    "start_offset": 53, 
    "end_offset": 57, 
    "type": "<ALPHANUM>", 
    "position": 6 
    }, 
    { 
    "token": "we", 
    "start_offset": 59, 
    "end_offset": 61, 
    "type": "<ALPHANUM>", 
    "position": 7 
    }, 
    { 
    "token": "had", 
    "start_offset": 62, 
    "end_offset": 65, 
    "type": "<ALPHANUM>", 
    "position": 8 
    }, 
    { 
    "token": "the", 
    "start_offset": 66, 
    "end_offset": 69, 
    "type": "<ALPHANUM>", 
    "position": 9 
    }, 
    { 
    "token": "happiest", 
    "start_offset": 70, 
    "end_offset": 78, 
    "type": "<ALPHANUM>", 
    "position": 10 
    }, 
    { 
    "token": "waiter", 
    "start_offset": 79, 
    "end_offset": 85, 
    "type": "<ALPHANUM>", 
    "position": 11 
    }, 
    { 
    "token": "and", 
    "start_offset": 86, 
    "end_offset": 89, 
    "type": "<ALPHANUM>", 
    "position": 12 
    }, 
    { 
    "token": "the", 
    "start_offset": 90, 
    "end_offset": 93, 
    "type": "<ALPHANUM>", 
    "position": 13 
    }, 
    { 
    "token": "crowd's", 
    "start_offset": 94, 
    "end_offset": 101, 
    "type": "<ALPHANUM>", 
    "position": 14 
    }, 
    { 
    "token": "always", 
    "start_offset": 102, 
    "end_offset": 108, 
    "type": "<ALPHANUM>", 
    "position": 15 
    }, 
    { 
    "token": "flowing", 
    "start_offset": 109, 
    "end_offset": 116, 
    "type": "<ALPHANUM>", 
    "position": 16 
    } 
    ] 
} 

不道理给我。我正在使用停止分析器,结果中为什么会显示“and”和“the”?我试图将停止分析仪更改为空白和标准,但是我得到与上述完全相同的结果。他们之间没有区别。但是,如果我针对Elasticsearch 5.x的实例运行完全相同的查询,则结果不再包含“and”和“the”,它看起来更像预期的那样。

这是因为我们使用1.7还是在我们的Elasticsearch设置中导致此问题?

编辑: 我使用感插件在Chrome做我的查询,和插件不支持请求的身体得到这样它改变了请求,POST。弹性分析API 1.7似乎不支持POST请求:(如果我改变这样的查询GET _analyze?analyzer = stop & text = THIS + is + a + test & pretty pretty works

回答

2

在1.x语法从2.x and 5.x不同根据1.x的documentation,你应该使用_analyze API这样的:。

GET _analyze?analyzer=stop 
{ 
    "text": "Extremely good food! We had the happiest waiter and the crowd's always flowing!" 
} 
+0

我只是想出了这个问题我自己,我使用感插件在Chrome做我的查询,并且该插件不支持使用请求主体的GET,因此它将请求更改为POST。Elastic Analyze API 1.7似乎不支持POST请求:(如果我更改查询是GET GET_analyze?analyzer = stop&text = THIS +是+ a + test&pretty它的工作原理 –

+0

您对Sense的评价是真实的,我在回复中提供的内容在Sense中进行了测试。如果我删除了'?analyzer = stop'部分并将其放在体内,它将不再工作,但文本将被分析,但不会使用'stop'分析器。 –

+0

哦,是的,我现在明白了:)但仍然更加整洁在2+ –