0

I am trying to have title field as both text and completion types in elastic search.

As shown below

PUT playlist
{
  "settings": {
    "number_of_shards": 2,
    "number_of_replicas": 2,
    "analysis": {
      "filter": {
        "custom_english_stemmer": {
          "type": "stemmer",
          "name": "english"
        },
        "english_stop": {
          "type": "stop",
          "stopwords": "_english_"
        }
      },
      "analyzer": {
        "custom_lowercase_analyzer": {
          "tokenizer": "standard",
          "filter": [
            "lowercase",
            "english_stop",
            "custom_english_stemmer"
          ]
        }
      }
    }
  },
  "mappings": {
    "properties": {
      "id": {
        "type": "long",
        "index": false,
        "doc_values": false
      },
      "title": {
        "type": "text",
        "analyzer": "custom_lowercase_analyzer",
        "fields": {
          "raw": {
            "type": "completion"
          }
        }
      }
    }
  }
}

The below suggestion query works

POST media/_search
{
  "_source": ["id", "title"], 
  "suggest": {
    "job-suggest": {
      "prefix": "sri",
      "completion": {
        "field": "title"
      }
    }
  }
}

But normal search would fail on the same title

GET media/_search
{
    "_source": ["id", "title"], 
    "query" : {
        "query_string": {
           "query" : "*sri*",
            "fields" : [
              "title"
            ]
        }
    }
}

Please help me solve this problem

Sharath
  • 2,348
  • 8
  • 45
  • 81
  • Can you show a sample document and what both queries return ? – Val May 01 '20 at 06:38
  • U should use n grams for completion, they are much better in terms of performance – Aditya Agarwal May 01 '20 at 10:31
  • any docs link for it ? – Sharath May 01 '20 at 11:26
  • @Sharath, I tried your queries with your index setting and mapping and it returned the correct result to me, it would be better if you provide sample documents and expected documents for us to understand better your requirements. – Amit May 02 '20 at 01:17

0 Answers0