模糊查询,返回整个字段中的特定术语

时间:2017-09-29 20:11:09

标签: elasticsearch

我正在向我的弹性搜索服务器执行此查询:

{
    "query": {
        "multi_match" : {
            "query" : "Onions",
            "fields": ["title_en", "description_en"],
            "fuzziness": "5"
        }
    },
    "_source": ["title_en", "description_en", "active", "id"],
    "size": 25
}

它运作良好,结果是:

{
    "took": 15,
    "timed_out": false,
    "_shards": {
        "total": 10,
        "successful": 10,
        "failed": 0
    },
    "hits": {
        "total": 2,
        "max_score": 0.99976414,
        "hits": [
            {
                "_index": "fmf",
                "_type": "menu",
                "_id": "18",
                "_score": 0.99976414,
                "_source": {
                    "description_en": "Delicious onions rings, the best flavors",
                    "active": true,
                    "title_en": "Onions rings",
                    "id": 18
                }
            },
            {
                "_index": "fmf",
                "_type": "menu",
                "_id": "16",
                "_score": 0.574256,
                "_source": {
                    "description_en": "A delectable array of our most popular starters that’s big enough to share. Served with different sauces for mixing and matching. Includes Onion Rings, Potato Skins, Tomato Bruschetta and Santa Fe Spring Rolls",
                    "active": true,
                    "title_en": "Jumbo combo veg",
                    "id": 16
                }
            }
        ]
    }
}

正如您所看到的,找到的结果是description_en并返回整个字段,但是存在一种只返回找到的字的方法吗? 就像,如果我搜索honyons(写得不好),只返回" Onion"而是所有的领域???

1 个答案:

答案 0 :(得分:0)

建议API似乎是您正在寻找的内容,尤其是term suggester

我同意评论,highlighting可能是一个解决方案。

顺便说一句,fuzziness为5是不可能的,它是AUTO,0,1或2。