Autocomplete in elasticsearch


(Mohamed Ärafath) #1

currently, I'm building autocomplete. here my elastic search query.

PUT test_index
{
  "settings": {
    "index": {
      "analysis": {
        "filter": {
          "stemmer": {
            "type": "stemmer",
            "language": "english"
          },
    
          "stopwords": {
            "type": "stop",
            "stopwords": [
              "_english_"
            ]
          }
        },
        "analyzer": {
          "autocomplete": {
            "filter": [
               [ "lowercase", "asciifolding" ]
            ],
            "char_filter": [
              "html_strip"
            ],
            "type": "custom",
            "tokenizer": "standard"
          },
          "default": {
            "filter": [
              "lowercase",
              "stopwords",
              "stemmer"
            ],
            "char_filter": [
              "html_strip"
            ],
            "type": "custom",
            "tokenizer": "standard"
          }
        }
      }
    }
  },
  "mappings": {
    "test_type": {
      "properties": {
        "autocomplete": {
          "type": "text",
          "analyzer": "autocomplete",
          "fielddata": true
        },
        "description": {
          "type": "text"
        }
        "title": {
          "type": "text",
          "copy_to": [
            "autocomplete"
          ]
        }
      }
    }
  }
}
  POST /test_index/test_type/1
{
  "title": "Apple iPhone 6+",
  "description": "some description"
}

POST /test_index/test_type/2
{
  "title": "Apple iPhone I Phone 5 Original",
 "description": "some description"
}
POST /test_index/test_type/3
{
  "title": "Apple iMac 21.5/2.8GHz/i5/8GB 2016",
  "description": "some description"
}
POST /test_index/test_type/4
{
  "title": "Apple i Phone 4S",
  "description": "some description"
}

POST /test_index/test_type/5
{
  "title": "Amazon kindle",
  "description": "some description"
}

POST /test_index/test_type/6
{
  "title": "Apploo i Phone 4S",
  "description": "some description"
}

#autocomplete
POST /test_index/_search/
{
"aggs": {
"autocomplete": {
"terms": {
"field": "autocomplete",
"order": {
"_count": "desc"
},
"include": "APP."
}
}
},
"query": {
"query_string": {
"query": "APP
",
"fields": [
"autocomplete"
]
}
}
}

This is not supported in case-sensitive, and whitespace search (I phone). If I search "I phone" or "APPLE" there is no aggregation result.


(Mark Harwood) #2

Have you looked at completion suggester?


(Mohamed Ärafath) #3

Yes. I tried with completion suggester. I want like https://www.gumtree.com search


(system) #4

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.