how to have multiple type single suggest

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

how to have multiple type single suggest

madan ram
I want multiple type suggest for single request, 
eq I have data about some article and profile user data. So when we type I need to suggest profile user as well as user data in  one request.

I tried 

curl -X PUT localhost:9200/suggestion -d '
{
  "mappings" : {
    "keyword" : {
      "properties" : {
        "name_suggest" : { "type" : "completion"}
      }
    },
    "profiles" : {
      "properties" : {
        "name_suggest" : { "type" : "completion"},
        "payload" : true
      }
    }
  }
}'

my request is
curl -X GET localhost:9200/suggestion/_suggest?pretty -d '
{
  "keyword" : {
    "text" : "a",
    "completion" : {
      "field" : "name_suggest"
    }
  },
  "profiles" : {
    "text" : "a",
    "completion" : {
      "field" : "name_suggest"
    }
  }
}'

It need to return

{
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "failed" : 0
  },
  "keyword" : [ {
    "text" : "a",
    "offset" : 0,
    "length" : 1,
    "options" : [ {
      "text" : "aba",
      "score" : 1.0
    }, {
      "text" : "abaca",
      "score" : 1.0
    }, {
      "text" : "abandoned land",
      "score" : 1.0
    }, {
      "text" : "abelmoschus esculentus",
      "score" : 1.0
    }, {
      "text" : "abies balsamea",
      "score" : 1.0
    } ]
  } ],
  "profiles" : [ {
    {
      "text" : "abhi dath",
      "score" : 1.0
    }, {
      "text" : "anney lotra",
      "score" : 1.0
    } ]
  } ]
}

but I get

{
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "failed" : 0
  },
  "keyword" : [ {
    "text" : "a",
    "offset" : 0,
    "length" : 1,
    "options" : [ {
      "text" : "aba",
      "score" : 1.0
    }, {
      "text" : "abaca",
      "score" : 1.0
    }, {
      "text" : "abandoned land",
      "score" : 1.0
    }, {
      "text" : "abelmoschus esculentus",
      "score" : 1.0
    }, {
      "text" : "abies balsamea",
      "score" : 1.0
    } ]
  } ],
  "profiles" : [ {
    "text" : "a",
    "offset" : 0,
    "length" : 1,
    "options" : [ {
      "text" : "aba",
      "score" : 1.0
    }, {
      "text" : "abaca",
      "score" : 1.0
    }, {
      "text" : "abandoned land",
      "score" : 1.0
    }, {
      "text" : "abelmoschus esculentus",
      "score" : 1.0
    }, {
      "text" : "abies balsamea",
      "score" : 1.0
    } ]
  } ]
}

what is wrong ?, Is there any other approach

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/0c7bb180-cbd0-4807-a172-acb6b5818b59%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: how to have multiple type single suggest

Michaël Gallego
Hi,

Suggester does not work the same way as normal queries and is not aware of types, so the output is expected. As you have two suggesters with same name, it will return the same results. You should use the context suggester, that adds a context (http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/suggester-context.html), so that you can differentiate. To avoid any ambiguity, I tend to have more verbose name for my suggesters are they are not type aware (so instead of "name_suggest" I would call them "keyword_name_suggest" and "profile_name_suggest"). If you do so, you basically don't need to use the "context suggester". If you want to keep the same name, you'll have to use a context suggester.

Hope it helps!

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/568f322f-39df-4967-ab03-69dfe6aa54bc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.