简体   繁体   中英

es query of suggest in elasticsearch 5.0.1

I have a question that i want to search a result use suggest. My type schema like this

`
{
    "name": {
        "input": [
            "uers1"
        ]
    },
    "usertype": 1
}{
    "name": {
        "input": [
            "uers2"
        ]
    },
    "usertype": 2
}`  

I want search data by suggest, the query like these

`{
    "suggest": {
        "person_suggest": {
            "text": "us",
            "completion": {
                "field": "name"
            }
        }
    }
}`  

And the result like these

`{
    "_shards": {
        "total": 1,
        "successful": 1,
        "failed": 0
    },
    "person_suggest": [
        {
            "text": "word",
            "offset": 0,
            "length": 4,
            "options": [
                {
                    "name": "user1",
                    "usertype": 1,
                    "score": 1
                },
                {
                    "text": "user2",
                    "usertype": 2,
                    "score": 1
                }
            ]
        }
    ]
} `

But I only want the result is usertype = 1, like add a where condition in mysql. Any body can help me ?I want a DSL query.Thx a lot.

You can'nt filter in completion suggest queries. A solution to your problem to make different completion fields for each usertype or use standard queries with nGram analyzers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM