Выполните точное совпадение с полем типа текста Elastic Search с несколькими значениями - PullRequest
0 голосов
/ 07 мая 2019

Привет, у меня есть миллионы повторов в упругом поиске, где одно из моих полей (textlowercase) имеет тип "текст".

Теперь я хочу найти в этом поле типа "текст" несколько слов, как я могу это сделать.

Проблема в том, что, поскольку это текстовое поле, оно анализируется и разбивается на токены. например, в SQL я хочу что-то вроде этого

select textlowercase from table where textlowercase like '%abc%' or '%bbc%' or '%my text%'

Я попытался «не анализировать», и изменение типа на «ключевое слово» не помогает.

Я использую Elastic search 7

Вот мои отображения:

{
  "settings": {
    "analysis": {
      "normalizer": {
        "lowercase_normalizer": {
          "type": "custom",
          "char_filter": [

          ],
          "filter": [
            "lowercase"
          ]
        }
      },
      "analyzer": {
        "my_analyzer": {
          "type": "custom",
          "tokenizer": "standard",
          "filter": [
            "lowercase"
          ]
        }
      }
    }
  },
  "fbdata": {
    "mappings": {
      "properties": {
        "createdatutc": {
          "type": "date",
          "format": "yyyy-MM-dd HH:mm:ss"
        },
        "createdbyname": {
          "type": "keyword"
        },
        "groupname": {
          "type": "keyword"
        },
        "id": {
          "type": "keyword"
        },
        "insertedatutc": {
          "type": "date",
          "format": "yyyy-MM-dd HH:mm:ss"
        },
        "postid": {
          "type": "keyword"
        },
        "posttype": {
          "type": "keyword"
        },
        "posturl": {
          "type": "keyword"
        },
        "textlowercase": {
          "type": "text",
          "analyzer": "my_analyzer",
          "fielddata": true
        }
      }
    }
  }
}

А вот и мой запрос

{
  "index": "fbdata",
  "type": "_doc",
  "body": {
    "from": 0,
    "size": 500000,
    "query": {
      "bool": {
        "should": [ {
          "match": {
            "textlowercase": "*cowmilk*"
          }
        }, {
          "match": {
            "textlowercase": "*Gaay ka doodh*"
          }
        }, {
          "match": {
            "textlowercase": "*cow ka*"
          }
        }, {
          "match": {
            "textlowercase": "*bakri ka*"
          }
        }, {
          "match": {
            "textlowercase": "*goatmilk*"
          }
        }],
        "must": [{
          "range": {
            "createdatutc": {
              "gte": "2019-01-01",
              "lt": "2019-03-31",
              "format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd"
            }
          }
        }]
      }
    }
  }
}

1 Ответ

1 голос
/ 07 мая 2019

Вы можете использовать запрос match_phrase.

{
  "query": {
    "match_phrase": {
      "FIELD": "PHRASE"
    }
  }
}

Подробнее https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query-phrase.html

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...