我刚刚开始从事elasticsearch的工作。我有一个索引"new_index“,映射如下:
"new_index" : {
"aliases" : { },
"mappings" : {
"current" : {
"properties" : {
"did" : {
"type" : "integer"
},
"fil_date" : {
"type" : "double"
},
"file_nr" : {
"type" : "double"
},
"id" : {
"type" : "integer"
},
"mark_text" : {
"type" : "text"
},
"mark_type_id" : {
"type" : "text"
},
"markdescr" : {
"type" : "text"
},
"markdescrtext" : {
"type" : "text"
},
"niceclmain" : {
"type" : "double"
},
"owname" : {
"type" : "text"
},
"statusapplication" : {
"type" : "text"
}
}
}
},
"settings" : {
"index" : {
"creation_date" : "1527665866982",
"number_of_shards" : "5",
"number_of_replicas" : "1",
"uuid" : "Py5uWzVTRYqcZuCLcwm-BQ",
"version" : {
"created" : "6020499"
},
"provided_name" : "new_index"
}
}
}
现在我想搜索字段"mark_text“。我有两种类型的搜索1.如果我搜索"smart",结果应该只包含不区分大小写的单词"smart“。2.它应该像我们使用的LIKE "%smart%“一样搜索,并且不区分大小写。
我已经得到了第二个搜索案例的查询。但是,我想知道是否有任何解决方案可以用于这两种搜索情况。
编辑:我用于搜索案例1的查询是:
GET _search
{
"query": {
"bool": {
"must" : [
{
"match": {
"mark_text": "smart"
}
}
]
}
}
}
查询搜索案例2:
GET _search
{
"query": {
"bool": {
"must" : [
{
"wildcard": {
"mark_text": "*smart*"
}
}
]
}
}
}
发布于 2018-05-31 18:24:13
我创建了一个新索引,并添加了映射和设置,如下所示:
{
"new_index5" : {
"aliases" : { },
"mappings" : {
"current" : {
"properties" : {
"did" : {
"type" : "integer"
},
"fil_date" : {
"type" : "double"
},
"file_nr" : {
"type" : "double"
},
"filing_date" : {
"type" : "double"
},
"id" : {
"type" : "integer"
},
"mark_identification" : {
"type" : "keyword",
"normalizer" : "lowercase_normalizer"
},
"mark_text" : {
"type" : "keyword",
"normalizer" : "lowercase_normalizer"
},
"mark_type_id" : {
"type" : "text"
},
"markdescr" : {
"type" : "text"
},
"markdescrtext" : {
"type" : "text"
},
"niceclmain" : {
"type" : "double"
},
"owname" : {
"type" : "keyword",
"normalizer" : "lowercase_normalizer"
},
"party_name" : {
"type" : "keyword",
"normalizer" : "lowercase_normalizer"
},
"primary_code" : {
"type" : "text"
},
"registration_date" : {
"type" : "double"
},
"registration_number" : {
"type" : "double"
},
"serial_number" : {
"type" : "double"
},
"status_code" : {
"type" : "text"
},
"statusapplication" : {
"type" : "text"
}
}
}
},
"settings" : {
"index" : {
"number_of_shards" : "5",
"provided_name" : "new_index5",
"creation_date" : "1527686957833",
"analysis" : {
"normalizer" : {
"lowercase_normalizer" : {
"filter" : [
"lowercase"
],
"type" : "custom",
"char_filter" : [ ]
}
}
},
"number_of_replicas" : "1",
"uuid" : "9YdUrs1cSBuqDJmvSPOm6g",
"version" : {
"created" : "6020499"
}
}
}
}
}
并在我的查询中为第一个搜索案例添加了聚合,如下所示:
GET _search
{
"query": {
"bool": {
"must" : [
{
"match": {
"mark_text": "smart"
}
}
]
}
},
"aggs": {
"mark_texts": {
"terms": {
"field": "mark_text"
}
}
}
}
它给我的结果包括“聪明”和“聪明”。
对于第二个搜索案例,我使用的是模糊。
我仍然不知道聚合和规格化是如何解决我的问题的。但是,我正在尝试去理解它。
https://stackoverflow.com/questions/50602321
复制相似问题