2
我希望能夠處理過度特定的搜索術語。因此,如果用戶搜索「稅收」,我希望能夠包括稅收以及標題字段中的結果。以下是我的Elasticsearch配置。我正在使用1.5版本。Elasticsearch處理特定術語
設置
{
"content_pages":{
"settings":{
"index":{
"creation_date":"1473848573964",
"analysis":{
"analyzer":{
"string_analyzer":{
"filter":[
"standard",
"lowercase",
"stop",
"asciifolding"
],
"char_filter":[
"html_strip"
],
"type":"custom",
"tokenizer":"standard"
}
}
},
"number_of_shards":"2",
"number_of_replicas":"0",
}
}
}
}
映射
"mappings":{
"content_page_type":{
"_all":{
"auto_boost":true
},
"properties":{
"author":{
"type":"integer"
},
"body:value":{
"type":"string",
"boost":13.0,
"analyzer":"string_analyzer"
},
"changed":{
"type":"date",
"format":"date_time"
},
"component":{
"type":"string",
"index":"not_analyzed",
"analyzer":"string_analyzer"
},
"content_page_tab_data":{
"type":"string",
"boost":13.0,
"analyzer":"string_analyzer"
},
"created":{
"type":"date",
"format":"date_time"
},
"field_aat_resource_type_taxonomy":{
"type":"integer"
},
"field_asset_file:file":{
"type":"integer"
},
"field_body:value":{
"type":"string",
"boost":13.0,
"analyzer":"string_analyzer"
},
"field_file_private:file":{
"type":"integer"
},
"field_study_resource_file:file":{
"type":"integer"
},
"field_tabs_page_body:value":{
"type":"string",
"boost":13.0,
"analyzer":"string_analyzer"
},
"id":{
"type":"integer",
"include_in_all":false
},
"level":{
"type":"string",
"index":"not_analyzed",
"analyzer":"string_analyzer"
},
"nid":{
"type":"integer"
},
"programme":{
"type":"string",
"index":"not_analyzed",
"analyzer":"string_analyzer"
},
"search_api_access_node":{
"type":"string",
"index":"not_analyzed",
"analyzer":"string_analyzer"
},
"search_api_language":{
"type":"string",
"index":"not_analyzed",
"analyzer":"string_analyzer"
},
"status":{
"type":"boolean"
},
"strand":{
"type":"string",
"index":"not_analyzed",
"analyzer":"string_analyzer"
},
"title":{
"type":"string",
"boost":21.0,
"analyzer":"string_analyzer"
},
"type":{
"type":"string",
"index":"not_analyzed",
"analyzer":"string_analyzer"
}
}
}
}
搜索查詢
{
"from":0,
"size":"10",
"query":{
"bool":{
"must":[
{
"multi_match":{
"query":"taxation",
"fields":[
"body:value^13.0",
"content_page_tab_data^13.0",
"field_body:value^13.0",
"field_tabs_page_body:value^13.0",
"title^21.0"
]
}
}
],
"should":[
{
"query_string":{
"query":"(taxation)",
"fields":[
"body:value^13.0",
"content_page_tab_data^13.0",
"field_body:value^13.0",
"field_tabs_page_body:value^13.0",
"title^21.0"
]
}
},
{
"fuzzy_like_this" : {
"fields" : ["title"],
"like_text" : "taxation",
"fuzziness": "AUTO"
}
}
]
}
}
}
上面的查詢不返回結果標題只包含「稅」但「稅」。我也不想包含諸如「關係」或「行動」等不相關的結果。