问题描述
你好,我在ES中面临两个问题- 我现在有一个'纽约''纽约',现在我想写一个术语过滤器,如果给定的字符串完全匹配纽约,那么只有它返回,但发生的是当我的过滤器匹配新或约克,它们都返回纽约,但它没有返回任何对于纽约,我的映射如下,请告诉我哪个分析器或分类器应该在映射中使用
这里是设置和映射:
设置:{
index:{
analysis:{
analyzer:{
synonym:{
tokenizer:whitespace,
filter:[synonym]
}
filter:{
synonym:{
type:synonym,
peers_path:synchronize.txt
}
}
}
}
},
映射:{
餐厅:{
属性:{
地址:{
属性:{
city:{type:string,analyzer:synonym},
}
}
}
}
-
第二个问题是,要使用通配符查询小写示例new *,那么ES不会返回任何东西,但是当我正在尝试搜索大写的例子New *现在它返回纽约现在我在这第二个案例我想写我的城市映射,以便当我搜索小写或大写为两个ES返回同样的事情,我看到忽略大小写,我已经把它设置为假的同义词,但仍然我无法搜索小写和大写。
同义词:{
type:syn onym,
peers_path:synchronize.txt,
ignore_case:true //看到这里
}
我相信你没有提供足够的细节,但希望我的尝试会产生你的问题,我会发布我认为应该向前迈进的一步:
映射:
PUT测试
{
设置:{
索引:{
分析:{
analyzer:{
synonym:{
tokenizer:whitespace,
filter:[
synonym
]
},
keyword_lowercase:{
type:custom,
tokenizer:keyword,
filter :[
小写
]
}
},
过滤器:{
同义词 :{
type:synonym,
peers_path:synchronize.txt,
ignore_case:true
}
}
}
},
mappings:{
restaurant:{
properties:{
address:{
properties:{
city:{
type:string,
analyzer:synonym,
fields
raw:{
type:string,
index:not_analyzed
},
raw_ignore_case:{
type:string,
analyzer:keyword_lowercase
}
}
}
}
}
}
}
}
}
测试数据:
POST / test / restaurant / 1
{
address:{city:New York}
}
POST / test / restaurant / 2
{
地址:{city:new york}
}
查询第一个问题:
GET / test / restaurant / _search
{
查询:{
过滤:{
过滤器:{
term:{
address.city.raw:纽约
}
}
}
}
}
查询第二个问题
GET / test / restaurant / _search
{
query:{
query_string:{
query:address.city.raw_ignore_case:new *
}
}
}
Hello all i am facing two problems in ES
- I have a 'city' 'New York' in ES now i want to write a term filter such that if given string exactly matches "New York" then only it returns but what is happening is that when my filter matches "New" OR "York" for both it returns "New York" but it is not returning anything for "New York" my mapping is given below please tell me which analyzer or tokenizer should i use inside mapping
Here are the settings and mapping:
"settings": {
"index": {
"analysis": {
"analyzer": {
"synonym": {
"tokenizer": "whitespace",
"filter": ["synonym"]
}
},
"filter": {
"synonym": {
"type": "synonym",
"synonyms_path": "synonyms.txt"
}
}
}
}
},
mappings : {
"restaurant" : {
properties:{
address : {
properties:{
city : {"type" : "string", "analyzer": "synonym"},
}
}
}
}
Second problem is that when i am trying to use wildcard query on lowercase example "new*" then ES is not returning not anything but when i am trying to search uppercase example "New*" now it is returning "New York" now i in this second case i want to write my city mappings such that when i search for lowercase or uppercase for both ES returns the same thing i have seen ignore case and i have set it to false inside synonyms but still i am not able to search for both lowercase and uppercases.
"synonym": { "type": "synonym", "synonyms_path": "synonyms.txt", "ignore_case": true // See here }
I believe you didn't provide enough details, but hoping that my attempt will generate questions from you, I will post what I believe it should be a step forward:
The mapping:
PUT test
{
"settings": {
"index": {
"analysis": {
"analyzer": {
"synonym": {
"tokenizer": "whitespace",
"filter": [
"synonym"
]
},
"keyword_lowercase": {
"type": "custom",
"tokenizer": "keyword",
"filter": [
"lowercase"
]
}
},
"filter": {
"synonym": {
"type": "synonym",
"synonyms_path": "synonyms.txt",
"ignore_case": true
}
}
}
}
},
"mappings": {
"restaurant": {
"properties": {
"address": {
"properties": {
"city": {
"type": "string",
"analyzer": "synonym",
"fields": {
"raw": {
"type": "string",
"index": "not_analyzed"
},
"raw_ignore_case": {
"type": "string",
"analyzer": "keyword_lowercase"
}
}
}
}
}
}
}
}
}
Test data:
POST /test/restaurant/1
{
"address": {"city":"New York"}
}
POST /test/restaurant/2
{
"address": {"city":"new york"}
}
Query for the first problem:
GET /test/restaurant/_search
{
"query": {
"filtered": {
"filter": {
"term": {
"address.city.raw": "New York"
}
}
}
}
}
Query for the second problem:
GET /test/restaurant/_search
{
"query": {
"query_string": {
"query": "address.city.raw_ignore_case:new*"
}
}
}
这篇关于在ES中如何编写映射,以便对小写和大写使用通配符查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!