[英]Elastic Search: simple query not returning expected results
I'm using Elasticsearch 2.2.0 but this also happens in 1.x versions. 我正在使用Elasticsearch 2.2.0,但是在1.x版本中也会发生这种情况。
One of the text fields contains the word google.com. 文本字段之一包含单词google.com。 When I try to search google, ElasticSearch doesn't return anything. 当我尝试搜索google时,ElasticSearch不会返回任何内容。 But if I search google.com it returns the document that contains it. 但是,如果我搜索google.com,它将返回包含它的文档。
My query is simple, something like this: 我的查询很简单,如下所示:
query: {
filtered: {
query: {
simple_query_string: {
query: "google"
}
}
}
}
What should I do to make Elastic search return the document when i search for google? 当我搜索Google时,应该怎么做才能使Elastic search返回文档?
I do this kind of query with "wildcard" query 我使用“通配符”查询进行这种查询
https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-wildcard-query.html https://www.elastic.co/guide/zh-CN/elasticsearch/reference/current/query-dsl-wildcard-query.html
{
"query": {
"bool": {
"must": {
"wildcard": {
"fieldname": "google*" // replace the fieldname her
}
}
}
}
}
I suggest reading the documentation about the _all
field, because the simple_query_string
uses this field when none are specified, which is your case. 我建议阅读有关_all
字段的文档 ,因为在simple_query_string
指定任何内容的情况下, simple_query_string
使用此字段,这是您的情况。
_all
is indexed by default with the standard
analyzer, which means that google.com
will not be split at .
默认情况下, standard
分析器会为_all
编制索引,这意味着google.com
将不会在处拆分.
and will be indexed as google.com
. 并将被索引为google.com
。 Which means that searching for google.com
will look for this term in your index whereas in your text you have google
. 这意味着搜索google.com
将在您的索引中查找该术语,而在您的文本中则包含google
。
Searching in Elasticsearch is not only about the query, but also about the way you index the data . 在Elasticsearch中进行搜索不仅与查询有关, 而且还与索引数据的方式有关 。 It may not be as simple as SQL query with LIKE but at the same time, ES gives you way more power at insert time than SQL. 它可能不像使用LIKE进行SQL查询那样简单,但是与此同时,ES在插入时比SQL提供了更多功能。
Depending on what you want from your simple_query
you have multiple options to choose from: 根据您对simple_query
可以有多种选择:
_all
field: 更改_all
字段的分析器: {
"settings": {
"analysis": {
"analyzer": {
"letter": {
"type": "custom",
"tokenizer": "letter",
"filter": [
"lowercase"
]
}
}
}
},
"mappings": {
"test": {
"_all": {
"analyzer": "letter"
}
and the query: 和查询:
"query": {
"simple_query_string": {
"query": "google"
}
}
field
and **use that field in query_string_query
: 更改您的field
的分析器,并**在query_string_query
使用该字段: {
"settings": {
"analysis": {
"analyzer": {
"letter": {
"type": "custom",
"tokenizer": "letter",
"filter": [
"lowercase"
]
}
}
}
},
"mappings": {
"test": {
"properties": {
"text": {
"type": "string",
"analyzer": "letter"
}
}
And the query: 和查询:
"query": {
"simple_query_string": {
"query": "google",
"fields": ["text"]
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.