在elasticSearch中, 如何为任何字段定义动态默认映射(字段未预定义),可以使用空格和不区分大小写的值进行搜索。
例如,如果我有两个文件:
PUT myindex/mytype/1
{
"transaction": "test"
}
和
PUT myindex/mytype/2
{
"transaction": "test SPACE"
}
我想执行以下查询:
Querying: "test", Expected result: "test"
Querying: "test space", Expected result "test SPACE"
我试图使用:
PUT myindex
{
"settings":{
"index":{
"analysis":{
"analyzer":{
"analyzer_keyword":{
"tokenizer":"keyword",
"filter":"lowercase"
}
}
}
}
},
"mappings":{
"test":{
"properties":{
"title":{
"analyzer":"analyzer_keyword",
"type":"string"
}
}
}
}
}
但是在寻找" test"。
时,它给了我两个文件答案 0 :(得分:0)
显然运行我的查询时出错: 这是我在使用多字段查询时遇到此问题的解决方案:
#any field mapping - not analyzed and case insensitive
PUT /test_index
{
"settings": {
"index": {
"analysis": {
"analyzer": {
"analyzer_keyword": {
"tokenizer": "keyword",
"filter": ["lowercase"]
}
}
}
}
},
"mappings": {
"doc": {
"dynamic_templates": [
{ "notanalyzed": {
"match_mapping_type": "string",
"mapping": {
"type": "string",
"analyzer":"analyzer_keyword"
}
}
}
]
}
}
}
#index test data
POST /test_index/doc/_bulk
{"index":{"_id":3}}
{"name":"Company Solutions", "a" : "a1"}
{"index":{"_id":4}}
{"name":"Company", "a" : "a2"}
#search for document with name “company” and a “a1”
POST /test_index/doc/_search
{
"query" : {
"filtered" : {
"filter": {
"and": {
"filters": [
{
"query": {
"match": {
"name": "company"
}
}
},
{
"query": {
"match": {
"a": "a2"
}
}
}
]
}
}
}
}
}