Elasticsearch多个分析仪无法正常工作

时间:2017-05-10 20:54:46

标签: elasticsearch lucene

我有一个小测试注册,标题如下: ' Santos(SAN)XAvaíFC(AVAI) - Canindé(圣保罗-SP)'

如果我尝试搜索任何字词,例如“ san ”或“ avai ”或“avaí”或“ santos < / strong>'它工作正常。但是如果我尝试搜索“ Santos(SAN)XAvaíFC(AVAI)”,它应该只返回1个reg并返回所有3个reg。

以下是测试数据: https://gist.github.com/PtkFerraro/83c4b693cf770c3320fe0530a4e1ddc7

这是分析仪&amp;制图 https://gist.github.com/PtkFerraro/eb3244bf8c589b234a13d7f2b693cf77

以下是搜索: https://gist.github.com/PtkFerraro/c0f8ed300566cce3b5118fff1522a421

提前致谢

{
    "settings": {
        "analysis": {
            "analyzer": {
                "title_default_analyzer": {
                    "type": "custom",
                    "tokenizer": "title_tokenizer",
                    "filter": ["lowercase","brazilian_filter","asciifolding"
                    ]
                },
                "title_snowball_analyzer": {
                    "type": "custom",
                    "tokenizer": "title_tokenizer",
                    "filter": ["lowercase","brazilian_filter","asciifolding","snowball"
                    ]
                },
                "title_shingle_analyzer": {
                    "type": "custom",
                    "tokenizer": "title_tokenizer",
                    "filter": ["lowercase","brazilian_filter","shingle","asciifolding"
                    ]
                },
                "title_ngram_analyzer": {
                    "type": "custom",
                    "tokenizer": "title_tokenizer",
                    "filter": ["lowercase","brazilian_filter","asciifolding","edge_ngram_filter"
                    ]
                },
                "title_search_analyzer": {
                    "type": "custom",
                    "tokenizer": "title_tokenizer",
                    "filter": ["lowercase","brazilian_filter","asciifolding"
                    ]
                }
            },
            "filter": {
                "brazilian_filter": {
                    "type": "stemmer",
                    "name": "brazilian",
                    "token_chars": ["letter", "digit"]
                },
                "edge_ngram_filter": {
                    "type": "edgeNGram",
                    "min_gram": 3,
                    "max_gram": 50,
                    "token_chars": ["letter", "digit"]
                }
            },
            "tokenizer": {
                "title_tokenizer": {
                    "type": "letter"
                }
            }
        }
    },
    "mappings": {
        "entersport": {
            "_all": {
                "enabled": false
            },
            "properties": {
                "is_adult": {
                    "type": "boolean"
                },
                "match_start": {
                    "type": "date"
                },
                "match_title": {
                    "type": "text",
                    "fields": {
                        "title": {
                            "type": "text",
                            "analyzer": "title_default_analyzer"
                        },
                        "snowball": {
                            "type": "text",
                            "analyzer": "title_snowball_analyzer"
                        },
                        "shingles": {
                            "type": "text",
                            "analyzer": "title_shingle_analyzer"
                        },
                        "ngrams": {
                            "type": "text",
                            "analyzer": "title_ngram_analyzer",
                            "search_analyzer": "title_search_analyzer"
                        }
                    }
                }
            }
        }
    }
}

1 个答案:

答案 0 :(得分:1)

您似乎希望支持两种不同类型的搜索:(1)您将单个字词(如sanavai与足球比赛标题匹配)和(2)精确词组匹配部分或全部比赛名称。

您正在使用的query string query被解析为单独的术语,因此在您的示例Santos (SAN) X Avaí FC (AVAI)中包含与所有3个示例文档匹配的X令牌,因为它们各自包含X

您的查询:

{
    "query_string": {
        "query": "Santos (SAN) X Avaí FC (AVAI)",
        "fields": [
            "title^10",
            "match_title.snowball^2",
            "match_title.shingles^2",
            "match_title.ngrams"
        ]
    }
}

如果您想匹配整个短语,则需要使用可执行此操作的查询。评论中提出了Match phrase queries。您还可以使用匹配查询,operator设置为and查询中的字词。这样您就可以使用相同的查询类型将avaiSantos (SAN) X Avaí FC (AVAI)匹配。

我认为你可能对这样的事情感到高兴:

{
  "query": {
    "multi_match" : {
      "query":      "Santos (SAN) X Avaí FC (AVAI)",
      "fields":     [
            "title^10",
            "match_title.snowball^2",
            "match_title.shingles^2",
            "match_title.ngrams"
        ],
        "operator":   "and" 
    }
  }
}