Предотвращение токенизации определенных буквенных символов в ElasticSearch - PullRequest
0 голосов
/ 18 июня 2019

Я бы хотел предотвратить токенизацию или остановку - и / для определенного поля.

Я думал, что у меня есть код для такого поведения:

"char_filters": {
    "type": "word_delimiter",
    "type_table": [
        "- => ALPHA",
        "/ => ALPHA"
    ]
},

Однако, это ошибки:

{
  "error": {
    "root_cause": [
      {
        "type": "illegal_argument_exception",
        "reason": "Token filter [char_filters] cannot be used to parse synonyms"
      }
    ],
    "type": "illegal_argument_exception",
    "reason": "Token filter [char_filters] cannot be used to parse synonyms"
  },
  "status": 400
}

Глядя онлайн, я нашел PatternReplaceFilterFactory и несколько других методов, однако они заменяют персонажей. Я хочу, чтобы переводчик обрабатывал эти два символа как строки.

Так что я бы хотел, чтобы строка 5/3mm была помечена как таковая. Не разбивается на 5 и 3mm.

Пожалуйста, кто-нибудь может посоветовать правильный путь для достижения этой цели? Вот упрощенный PUT и некоторые запросы POST / Analyze.

// doc 1 contains what I would like to match
POST /products_example/_doc/1
{
  "ProductDescription_stripped":"RipCurl 5/3mm wetsuit omega",
  "ProductDescription_da_stripped": "RipCurl 5/3mm wetsuit omega"
}

// doc 2 contains only 3mm. Should be prioritised below 5/3mm (match 1)
POST /products_example/_doc/2
{
  "ProductDescription_stripped":"RipCurl 3mm wetsuit omega",
  "ProductDescription_da_stripped": "RipCurl 5/3mm wetsuit omega"
}

// here you can see 3mm have been tokenised where as 5/3mm should have been preserved
POST /products_example/_analyze
{
  "tokenizer": "standard",
  "filter":  [ "lowercase","asciifolding","synonym","stop","kstem"],
  "text":      "5/3mm ripcurl wetsuit omega"
}



PUT /products/
{

"settings": {
    "index.mapping.total_fields.limit": 1000000,
    "index.max_ngram_diff" : 2,

    "analysis": {

        "filter": {
            "char_filters": {
                "type": "word_delimiter",
                "type_table": [
                    "- => ALPHA",
                    "/ => ALPHA"
                ]
            },

            "description_stemmer_da" : {"type" : "stemmer","name" : "danish"},
            "stop_da" : {"type" : "stop","stopwords":  "_danish_"},
            "synonym" : {
                "type" : "synonym",
                "synonyms" : ["ripcurl, ripccurl => rip curl"]
            }
        },

        "tokenizer": {
            "ngram_tokenizer": {
                "type": "ngram", "min_gram": 3, "max_gram": 5,
                "token_chars": ["letter","digit"]
            }
        },

        "analyzer": {
            "description" : {
                "type": "custom", 
                "tokenizer": "standard",
                "filter": [
                    "char_filters",
                    "lowercase",
                    "asciifolding",
                    "synonym",
                    "stop",
                    "kstem"
                ]
            },

            "description_da": {
                "type":"custom", "tokenizer":"standard",
                "filter": [
                    "char_filters",
                    "lowercase",
                    "asciifolding",
                    "synonym",
                    "stop_da",
                    "description_stemmer_da"
                ]
            }
        }
    }
},

"mappings": {
    "properties": {

         "ProductDescription_stripped": {
            "type": "text",
            "analyzer" : "description"
        },
        "ProductDescription_da_stripped": {
            "type": "text",
            "analyzer": "danish"
        }
    }
}
}
...