0

I am trying to work with Python Elasticsearch version 1.1.0, on the master branch. It seems it will create an index, but there are issues with retrieving autocomplete results, when using a suggestion filed.

Below is a basic Python functions to create an index, then add a song to it, and finally we query it through the curl at the very bottom.

Unfortunately it fails with the error:

"reason" : "BroadcastShardOperationFailedException[[music][2] ]; nested: ElasticsearchException[failed to execute suggest]; nested: ElasticsearchException[Field [suggest] is not a completion suggest field]; "
    } ]'

The functions I am using to create the index and add a song is below:

conn = Elasticsearch()

def mapping():
    return """{
          "song" : {
                "properties" : {
                    "name" : { "type" : "string" },
                    "suggest" : { "type" : "completion",
                                  "index_analyzer" : "simple",
                                  "search_analyzer" : "simple",
                                  "payloads" : true
                    }
                }
            }
        }"""

def createMapping():
    settings = mapping()
    conn.indices.create(index= "music", body=settings)

def addSong():
    body = """{
        "name" : "Nevermind",
        "suggest" : {
            "input": [ "Nevermind", "Nirvana" ],
            "output": "Nirvana - Nevermind",
            "payload" : { "artistId" : 2321 },
            "weight" : 34
        }
    }"""

    res = conn.index(body=body, index="music", doc_type="song", id=1)

Curl request:

curl -X POST 'localhost:9200/music/_suggest?pretty' -d '{
    "song-suggest" : {
        "text" : "n",
        "completion" : {
            "field" : "suggest"
        }
    }
}'

1 Answer 1

0

When you use the create index API, you have to wrap your mappings in mappings:

def createMapping():
    settings = """{"mappings": %s}""" % mapping()
    conn.indices.create(index= "music", body=settings)
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.