Elasticsearch同义词搜索synonym.txt格式

时间:2019-05-30 08:30:39

标签: elasticsearch

我试图手动将同义词放入索引中,但是我没有得到输出。是否有任何原因为什么我没有得到想要的输出?我也尝试给出了analysis / wn_s.pl路径。手动添加同义词,好像有什么问题,无论是通过我的索引还是在查询。这是我的下面的索引,同义词搜索适用于“类别名称”字段。自动完成,模糊和Edgengram应用于“名称”字段。

{
    "settings": {
        "index": {
            "analysis": {
                "filter": {
                    "synonym": {
                        "type": "synonym",
                        "format": "wordnet",
                        "synonyms_path": "analysis/wn_s.pl"
                    }

                },
                "analyzer": {
                    "synonym": {
                        "tokenizer": "standard",
                        "filter": ["lowercase",
                            "synonym"
                        ]
                    },

                    "keyword_analyzer": {
                        "filter": [
                            "lowercase",
                            "asciifolding",
                            "trim"
                        ],
                        "char_filter": [],
                        "type": "custom",
                        "tokenizer": "keyword"
                    },
                    "edge_ngram_analyzer": {
                        "filter": [
                            "lowercase"
                        ],
                        "tokenizer": "edge_ngram_tokenizer"
                    },
                    "edge_ngram_search_analyzer": {
                        "tokenizer": "lowercase"
                    }
                },

                "tokenizer": {
                    "edge_ngram_tokenizer": {
                        "type": "edge_ngram",
                        "min_gram": 1,
                        "max_gram": 25,
                        "token_chars": [
                            "letter"
                        ]
                    }

                },
                "mappings": {
                    "properties": {
                        "firebaseId": {
                            "type": "text"
                        },
                        "name": {
                            "fielddata": true,
                            "type": "text",
                            "analyzer": "standard"
                        },
                        "name_auto": {
                            "type": "text",

                            "fields": {
                                "keywordstring": {
                                    "type": "text",
                                    "analyzer": "keyword_analyzer"
                                },
                                "edgengram": {
                                    "type": "text",
                                    "analyzer": "edge_ngram_analyzer",
                                    "search_analyzer": "edge_ngram_search_analyzer"
                                },
                                "completion": {
                                    "type": "completion"
                                }

                            }
                        },

                        "category_name": {
                            "type": "text",
                            "analyzer": "synonym"

                        },
                        "sku": {
                            "type": "text"
                        },
                        "price": {
                            "type": "text"
                        },
                        "magento_id": {
                            "type": "text"
                        },
                        "seller_id": {
                            "type": "text"
                        },
                        "square_item_id": {
                            "type": "text"
                        },
                        "square_variation_id": {
                            "type": "text"
                        },
                        "typeId": {
                            "type": "text"
                        }
                    }
                }
            }
        }
    }
}

我正在使用以下查询进行查询:

{
    "query": {
        "bool": {
            "should": [{
                    "match_phrase": {
                        "name_auto.edgengram": "shoes"
                    }
                }, {
                    "match_phrase": {
                        "name_auto": "shoes"
                    }
                },

                {
                    "match": {
                        "name_auto": "shoes"
                    }
                },
                {
                    "match": {
                        "category_name": {
                            "query": "shoes",
                            "analyzer": "synonym"

                        }
                    }
                }, {
                    "match_phrase": {
                        "category_name": "shoes"
                    }
                }, {
                    "match": {
                        "name": {
                            "query": "shoes",
                            "fuzziness": 2,
                            "prefix_length": 1

                        }
                    }
                }
            ]
        }
    }
}

0 个答案:

没有答案