Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Completion_fields: Enable the storing of payloads, defaults to false #25

Open
amitksaini78 opened this issue Oct 7, 2015 · 5 comments

Comments

@amitksaini78
Copy link

complete is an awesome api. However lack of payload (basically document id) renders it useless for many usecases.

Basically: Enable the storing of payloads, it defaults to false.

For example:
a. Tag.es.complete('name', 'p')
[u'Play/Outdoor', u'Performing Arts', u'Personality', u'Phonetics', u'Phonics']

b. City.es.complete('city', 'n')
[u'New Delhi']

However, without payload (document id's) its not usable for multiple usecases where the id is passed along to the client/in the workflow.

Checked the mappings for a connection_field city:
"city_complete": {
"max_input_length": 50,
"payloads": false,
"analyzer": "simple",
"preserve_position_increments": true,
"type": "completion",
"preserve_separators": true
},

@lauxley
Copy link
Contributor

lauxley commented Dec 1, 2015

I like the idea and it seems straightforward if we just switch from false to true, since we return the data almost as is anyway. But it gets a little bit trickier if we need to provide the option.

@LiamK
Copy link

LiamK commented Feb 11, 2017

Well, this is exactly what I need now.
I've got the completion suggester working, but without the payload document id (in fact, it is a city, like in the example above) I can't do anything with the result.
Is anyone working on this project any more?
If not, what are alternate means of accomplishing this?
Any help very much appreciated :-)

@lauxley
Copy link
Contributor

lauxley commented Feb 14, 2017

Hello,
Unfortunately there is no good way to do this out of the box. the completion field mapping is pretty much hard coded for now, but you can change it manually in your elasticsearch index, just switch the value of the 'payloads' key to 'true'. If you absolutely need this to be replicable you need to add "payloads": True to this line via a PR (if you are ok with deploying from a branch) or fork.

Nobody is working on this at the moment because even though it works pretty well out of the box and is well battle tested, the number of implemented features is too narrow to make it usable in most cases but the most basic ones, and the amount of work to change that is still quite substantial for one individual :)

@LiamK
Copy link

LiamK commented Feb 16, 2017

I tried this, but there must be something obvious I'm missing.
I added the payloads:True to the line in manager.py.
My class looks like this:

class Location(EsIndexable, models.Model):
    """A generic location which is either a city or an airport.
       Note: slug is not unique.
    """
    name = models.CharField(max_length=200, help_text="Name", blank=True)
    region = models.CharField(max_length=200, help_text="Region", blank=True)
    country = models.CharField(max_length=2, help_text="Country code", blank=True)
    city = models.ForeignKey('cities.City', null=True, blank=True,
            related_name='r_cities')
    airport = models.ForeignKey('airports.Airport', null=True, blank=True,
            related_name='r_airports')
    location = models.PointField(blank=True)

    class Elasticsearch(EsIndexable.Elasticsearch):
        mapping = {
            u'name_complete': {
                u'preserve_separators': True,
                u'analyzer': u'simple',
                u'payloads': True,
                u'max_input_length': 50,
                u'preserve_position_increments': True,
                u'type': u'completion'},
            u'name': {u'type': u'string'}
        }
        completion_fields = ['name']

Not sure if I need the extra mapping field, or not.
When I test it, though, I'm still getting just strings, no payloads.

>>> Location.es.flush()
>>> Location.es.do_update()
>>> Location.es.reindex_all()
>>> Location.es.complete('name', 'san')
[u'Sacramento', u'Salt Lake City', u'San Bruno', u'San Diego', u'San Francisco']

@lauxley
Copy link
Contributor

lauxley commented Feb 17, 2017

Well i can't really test it now but maybe there is something to change in the complete() method, or add some logging and check what elaticsearch returns.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants