Skip to content

Instantly share code, notes, and snippets.

@TomonoriSoejima
Last active November 6, 2020 12:24
Show Gist options
  • Save TomonoriSoejima/d4ca1699a19c08bf1193fa92a18422d8 to your computer and use it in GitHub Desktop.
Save TomonoriSoejima/d4ca1699a19c08bf1193fa92a18422d8 to your computer and use it in GitHub Desktop.
delete t
PUT /t
{
  "settings": {
    "index": {
      "analysis": {
        "filter": {
          "engram": {
            "type": "edgeNGram",
            "min_gram": 3,
            "max_gram": 255
          }
        },
        "analyzer": {
          "my_analyzer": {
            "type": "custom",
            "tokenizer": "keyword",
            "filter": [
              "nGram"
            ]
          }
        }
      }
    }
  },
  "mappings": {
    "t": {
      "properties": {
        "content": {
          "type": "text",
          "term_vector": "with_positions_offsets",
          "fields": {
            "ngram": {
              "type": "text",
              "analyzer": "my_analyzer",
              "fielddata": true
            }
          }
        }
      }
    }
  }
}




PUT t/t/1
{
  "content" : "hello"
}

GET t/_search
{
  "query": {
    "query_string": {
      "query": "hello",
      "lenient": true,
      "default_operator": "AND",
      "fields": [
        "content"
      ]
    }
  },
  "docvalue_fields": [
    "content.ngram",
    "test.keyword"
  ]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment