弹性搜索用连字符搜索一个字 [英] ElasticSearch searching with hyphen inside a word
问题描述
'body'=> array(
'mappings'=> array(
'myindex'=>数组(
'_source'=>数组(
'enabled'=> true
),
'properties'=> array(
'Title'=>数组(
'type'=>'string',
' =>数组(
'raw'=>数组(
'type'=>'string',
'index'=>'not_analyzed'
)
)
),
'Content'=>数组(
'type'=>'string'
),
'Image'=> ; array(
type'=>'string',
'analyzer'=>'standard'
)
)
)
)
)
查询字符串看起来像这样,我想要的是搜索15- g内的文字,如15游戏:
query:{
query_string:{
query:* 15-g *,
fields:[Title,Content]
}
}
如果我重复了这个问题,请接受我的道歉,但是我找不到发生了什么,为什么不返回任何结果。
我已经看了at:
但是我不能与我一起工作。
真正有趣的是什么是,如果我搜索15-g(15 空格 - 空格 g),则返回结果。
谢谢你提前!
添加 .raw
字段到您的内容
,并在 .raw
字段中进行搜索:
{
查询:{
query_string:{
查询:* 15-g * ,
fields:[
Title.raw,
Content.raw
]
}
}
}
在您要搜索的文本中您有空格的任何位置想要匹配您的字段的空间,需要转义(使用 \
)。此外,任何时候你都有大写字母和通配符,并且你想要像 .raw
字段匹配,你需要设置 lowercase_expanded_terms
到 false
,因为默认情况下该设置是 true
,它会缩小搜索字符串(将搜索对于笔记本电脑 - 黑色
):
{
查询:{
query_string:{
query:* Laptop \\\\\\ Black *,
lowercase_expanded_terms:false,
fields:[
Title.raw,
Content.raw
]
}
}
}
I would like to ask for a help. I want to search for a words inside the Title and Content. Here is the structure
'body' => array(
'mappings' => array(
'myindex' => array(
'_source' => array(
'enabled' => true
),
'properties' => array(
'Title' => array(
'type' => 'string',
'fields'=> array(
'raw' => array(
'type' => 'string',
'index' => 'not_analyzed'
)
)
),
'Content' => array(
'type' => 'string'
),
'Image' => array(
type' => 'string',
'analyzer' => 'standard'
)
)
)
)
)
And the query string looks like this, where I want so search for "15-g" inside a text like "15-game":
"query" : {
"query_string": {
"query": "*15-g*",
"fields": [ "Title", "Content" ]
}
}
Please accept my apologize if I duplicate the question but I cannot find out what's going on and why it does not return any results.
I've already had a look at:
ElasticSearch - Searching with hyphens
But I can't make to work that with me.
What is really interesting is that if I search for "15 - g" (15space-spaceg) it returns the result.
Thank you so much in advance!
Add a .raw
field to your Content
as well and make the search on the .raw
fields:
{
"query": {
"query_string": {
"query": "*15-g*",
"fields": [
"Title.raw",
"Content.raw"
]
}
}
}
Anywhere you have a space in the text you want to search and you want that space to match your fields, it needs to be escaped (with \
). Also, anytime you have upper case letter and wildcards and you want to match like that with the .raw
fields you need to set lowercase_expanded_terms
to false
, because by default that setting is true
and it will lowercase the search string (it will search for laptop - black
):
{
"query": {
"query_string": {
"query": "*Laptop\\ -\\ Black*",
"lowercase_expanded_terms": false,
"fields": [
"Title.raw",
"Content.raw"
]
}
}
}
这篇关于弹性搜索用连字符搜索一个字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!