Elasticsearch filtered completion suggester


(Zaid Amir) #1

Hi,

I am trying to add a filter to a completion suggester. My case is a s
follows:

My index follows the user data flow pattern, but instead of users I have
accounts. Each account has its own alias and can consist of multiple number
of users that share the same document. Each document has an identification
field that correspond to the user who indexed that document.

What I want is to find a way that when a user enters some text in the
search box. The completion suggester will only return suggestions from
documents that have that user's ID.

Lets assume this example:

curl -XPUT "http://localhost:9200/account1/photos/_mapping" -d'
{
"photos": {
"properties": {
"userid": {
"type": "long"
},
"name": {
"type": "string"
},
"size": {
"type": "long"
},
"createDate": {
"type": "date",
"format": "dateOptionalTime"
},
"tags": {
"type": "string"
},
"suggest": {
"type": "completion",
"index_analyzer": "simple",
"search_analyzer": "simple",
"payloads": false
}
}
}
}'

Now lets assume user 1 has indexed a photo:
curl -XPUT "http://localhost:9200/account1/photos/1" -d'
{
"userid": 1,
"name": "somephoto.jpg",
"size": 10000,
"tags": [
"paris",
"noon"
],
"suggest": {
"input": [
"paris",
"noon"
]
},
"createDate": "2013-12-19"
}'

Now user 2 has also indexed a new photo:

curl -XPUT "http://localhost:9200/account1/photos/2" -d'
{
"userid": 2,
"name": "somephoto.jpg",
"size": 10000,
"tags": [
"london",
"night"
],
"suggest": {
"input": [
"london",
"night"
]
},
"createDate": "2013-12-19"
}'

Now what I want to do is when user 1 enters the text "lon" in the search
box, the suggester will return NO autocomplete suggestions. Yet when he
enters the test "par" the suggester will return "paris".

Is there anyway to do this?

--
Please update your bookmarks! We have moved to https://discuss.elastic.co/

You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/93b62d01-60cd-4d7c-a68d-ed7edb987122%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(André Carvalho) #2

I think the suggester context is a good bet to your use case: (
https://www.elastic.co/guide/en/elasticsearch/reference/1.5/suggester-context.html
).

André Carvalho

+55 21 98739-1097 / br.linkedin.com/in/andrestc/

2015-05-18 3:06 GMT-03:00 Zaid Amir redserpent7@gmail.com:

Hi,

I am trying to add a filter to a completion suggester. My case is a s
follows:

My index follows the user data flow pattern, but instead of users I have
accounts. Each account has its own alias and can consist of multiple number
of users that share the same document. Each document has an identification
field that correspond to the user who indexed that document.

What I want is to find a way that when a user enters some text in the
search box. The completion suggester will only return suggestions from
documents that have that user's ID.

Lets assume this example:

curl -XPUT "http://localhost:9200/account1/photos/_mapping" -d'
{
"photos": {
"properties": {
"userid": {
"type": "long"
},
"name": {
"type": "string"
},
"size": {
"type": "long"
},
"createDate": {
"type": "date",
"format": "dateOptionalTime"
},
"tags": {
"type": "string"
},
"suggest": {
"type": "completion",
"index_analyzer": "simple",
"search_analyzer": "simple",
"payloads": false
}
}
}
}'

Now lets assume user 1 has indexed a photo:
curl -XPUT "http://localhost:9200/account1/photos/1" -d'
{
"userid": 1,
"name": "somephoto.jpg",
"size": 10000,
"tags": [
"paris",
"noon"
],
"suggest": {
"input": [
"paris",
"noon"
]
},
"createDate": "2013-12-19"
}'

Now user 2 has also indexed a new photo:

curl -XPUT "http://localhost:9200/account1/photos/2" -d'
{
"userid": 2,
"name": "somephoto.jpg",
"size": 10000,
"tags": [
"london",
"night"
],
"suggest": {
"input": [
"london",
"night"
]
},
"createDate": "2013-12-19"
}'

Now what I want to do is when user 1 enters the text "lon" in the search
box, the suggester will return NO autocomplete suggestions. Yet when he
enters the test "par" the suggester will return "paris".

Is there anyway to do this?

--
Please update your bookmarks! We have moved to https://discuss.elastic.co/

You received this message because you are subscribed to the Google Groups
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/93b62d01-60cd-4d7c-a68d-ed7edb987122%40googlegroups.com
https://groups.google.com/d/msgid/elasticsearch/93b62d01-60cd-4d7c-a68d-ed7edb987122%40googlegroups.com?utm_medium=email&utm_source=footer
.
For more options, visit https://groups.google.com/d/optout.

--
Please update your bookmarks! We have moved to https://discuss.elastic.co/

You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/CACigSzL0RK5Yd%3DH49y1amZ1ZFaQ8J002XOPGzJx%2B2Hts8CP1vg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


(system) #3