zoukankan      html  css  js  c++  java
  • Elasticsearch.Net 异常:[match] query doesn't support multiple fields, found [field] and [query]

    用Elasticsearch.Net检索数据,报异常:

    var settings = new ConnectionConfiguration(new Uri("http://localhost:9200")).RequestTimeout(TimeSpan.FromMinutes(2));
    
    ElasticLowLevelClient client = new ElasticLowLevelClient(settings);
    
    var searchResponse = client.Search<StringResponse>("test", "Person", PostData.Serializable(new
    {
        from = 0,
        size = 10,
        query = new { match = new { field = "name", query = "chenzongyan" }}
    }));
    
    string body = searchResponse.Body;
    Console.WriteLine(body);
    Console.ReadKey();

    异常信息:

    {
        "error": {
            "root_cause": [
                {
                    "type": "parsing_exception",
                    "reason": "[match] query doesn't support multiple fields, found [field] and [query]",
                    "line": 1,
                    "col": 62
                }
            ],
            "type": "parsing_exception",
            "reason": "[match] query doesn't support multiple fields, found [field] and [query]",
            "line": 1,
            "col": 62
        },
        "status": 400
    }

    解决办法:

    var searchResponse = client.Search<StringResponse>("test", "Person", PostData.Serializable(new
                {
                    from = 0,
                    size = 10,
                    query = new
                    {
                        multi_match = new
                        {
                            fields = "name",
                            query = "chenzongyan"
                        }
                    }
                }));
    

     将match 改为 multi_match ,field改为fields.

      检索结果:

    {
        "took": 2,
        "timed_out": false,
        "_shards": {
            "total": 5,
            "successful": 5,
            "skipped": 0,
            "failed": 0
        },
        "hits": {
            "total": 1,
            "max_score": 0.2876821,
            "hits": [
                {
                    "_index": "test",
                    "_type": "Person",
                    "_id": "WOgCs2UBfhVuaFPoccea",
                    "_score": 0.2876821,
                    "_source": {
                        "name": "chenzongyan",
                        "Age": 27
                    }
                }
            ]
        }
    }
    

    参考:https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/elasticsearch-net-getting-started.html

  • 相关阅读:
    Linux下搭建socks5代理
    在vs2005 使用FreeTextBox
    毕业了!!
    ASP.net 2.0上传图片方法
    再网页中,怎么用VS2005中的日历空件输入日期格式!
    毕业设计!!
    学校终于放假了,今天就可以回家了!
    求职!本人是07届刚毕业的学生!求程序员
    libcurl教程(转)
    spring boot集成swagger3
  • 原文地址:https://www.cnblogs.com/chenzongyan/p/9625967.html
Copyright © 2011-2022 走看看