duanbinren8906 2015-07-30 22:09
浏览 57

在ElasticSearch中使用什么DSL查询?

I use PHP library for ElasticSearch. I have added documents in index as:

$document = array('name' => 'Bob', 'family' => 'Bobsters', 'car' => 'Mersedes');

What kind of query I need to use if I want to get search result after entered symbol: B.

It request whould be return result with name Bob and other result that are started from symbol B.

  • 写回答

1条回答 默认 最新

  • dourong6054 2015-07-30 23:18
    关注

    More information is required for a comprehensive answer, as you can customize the index/type/fields you search on etc., and create a more efficient query with additional parameters, as a wildcard query is very expensive, especially if only wildcarding one letter, and if you wildcarding at the end of a query string.

    This is bad. I realize there is an excessive use of bolding, however it's hard to overstate how expensive wildcarding at the end of a querystring (and only one letter at that) is.

    You can read about wildcard queries here.

    As always with these questions it is good to mention search as you type functionality which is often the end goal, docs found here.

    Below is a basic wildcard query that will fulfill the original function you are asking for.

    POST /my_index/my_type/_search
    {
       "query": {
           "wildcard": {
              "name": {
                "value": "B*"
             }
          }
       }
    }
    

    This will return all documents with the name field starting with B.

    Edit in response to comments:

    If you are not interested in wildcard query, you may use the prefix query.

    POST /my_index/my_type/_search
    {
       "query": {
           "prefix": {
              "name": "B"
           }
       }
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?