弹性搜索多个字段中的多个关键字

埃桑·希尔扎迪(ehsan shirzadi)

我试图在Elastic搜索中构建一个查询,以在多个字段的文本内进行搜索,例如:Title和Description是字段,我想在这3个字段内搜索“ obama”,“ world”,“ news”。我尝试在Elastic网站上搜索并找到信息:
http : //www.elasticsearch.org/guide/zh-CN/elasticsearch/reference/current/query-dsl-multi-match-query.html#_literal_fields_literal_and_per_field_boosting但是问题是当我尝试这种结构时,它会产生错误:
首先:

{
  "multi_match" : {
    "query":      "obama world news",
    "type":       "cross_fields",
    "fields":     [ "Title", "Description" ],
    "operator":   "and"
  }
}

它产生如下错误:

{
    "error": "SearchPhaseExecutionException[Failed to execute phase [query], all shards failed; shardFailures {[0CTkBM0pQGK1MzYEDlrpcQ][republishan2][0]: SearchParseException[[republishan2][0]: from[-1],size[-1]: Parse Failure [Failed to parse source [    {\n      \"multi_match\" : {\n        \"query\":      \"obama world news\",\n        \"type\":       \"cross_fields\",\n        \"fields\":     [ \"Title\", \"Description\" ],\n        \"operator\":   \"and\"\n      }\n    }]]]; nested: SearchParseException[[republishan2][0]: from[-1],size[-1]: Parse Failure [No parser for element [multi_match]]]; }{[0CTkBM0pQGK1MzYEDlrpcQ][republishan2][3]: SearchParseException[[republishan2][3]: from[-1],size[-1]: Parse Failure [Failed to parse source [    {\n      \"multi_match\" : {\n        \"query\":      \"obama world news\",\n        \"type\":       \"cross_fields\",\n        \"fields\":     [ \"Title\", \"Description\" ],\n        \"operator\":   \"and\"\n      }\n    }]]]; nested: SearchParseException[[republishan2][3]: from[-1],size[-1]: Parse Failure [No parser for element [multi_match]]]; }{[0CTkBM0pQGK1MzYEDlrpcQ][republishan2][4]: SearchParseException[[republishan2][4]: from[-1],size[-1]: Parse Failure [Failed to parse source [    {\n      \"multi_match\" : {\n        \"query\":      \"obama world news\",\n        \"type\":       \"cross_fields\",\n        \"fields\":     [ \"Title\", \"Description\" ],\n        \"operator\":   \"and\"\n      }\n    }]]]; nested: SearchParseException[[republishan2][4]: from[-1],size[-1]: Parse Failure [No parser for element [multi_match]]]; }{[0CTkBM0pQGK1MzYEDlrpcQ][republishan2][1]: SearchParseException[[republishan2][1]: from[-1],size[-1]: Parse Failure [Failed to parse source [    {\n      \"multi_match\" : {\n        \"query\":      \"obama world news\",\n        \"type\":       \"cross_fields\",\n        \"fields\":     [ \"Title\", \"Description\" ],\n        \"operator\":   \"and\"\n      }\n    }]]]; nested: SearchParseException[[republishan2][1]: from[-1],size[-1]: Parse Failure [No parser for element [multi_match]]]; }{[0CTkBM0pQGK1MzYEDlrpcQ][republishan2][2]: SearchParseException[[republishan2][2]: from[-1],size[-1]: Parse Failure [Failed to parse source [    {\n      \"multi_match\" : {\n        \"query\":      \"obama world news\",\n        \"type\":       \"cross_fields\",\n        \"fields\":     [ \"Title\", \"Description\" ],\n        \"operator\":   \"and\"\n      }\n    }]]]; nested: SearchParseException[[republishan2][2]: from[-1],size[-1]: Parse Failure [No parser for element [multi_match]]]; }]",
    "status": 400
}

我也尝试过以下查询:

{
    "sort": {
        "re_max": {
            "order": "desc"
            }
            }, 
    "query": {
      "multi_match" : {
        "query":      "obama world news",
        "type":       "cross_fields",
        "fields":     [ "Title", "Description" ],
        "operator":   "and"
      }
    },
    "from": 0, 
    "size": 30}
}

结果如下:

{
    "error": "SearchPhaseExecutionException[Failed to execute phase [query], all shards failed; shardFailures {[0CTkBM0pQGK1MzYEDlrpcQ][republishan2][0]: SearchParseException[[republishan2][0]: from[-1],size[-1],sort[<custom:\"re_max\": org.elasticsearch.index.fielddata.fieldcomparator.LongValuesComparatorSource@1ef6a497>!]: Parse Failure [Failed to parse source [{\n\t\"sort\": {\n\t\t\"re_max\": {\n\t\t\t\"order\": \"desc\"\n\t\t\t}\n\t\t\t}, \n\t{\n      \"multi_match\" : {\n        \"query\":      \"obama world news\",\n        \"type\":       \"cross_fields\",\n        \"fields\":     [ \"Title\", \"Description\" ],\n        \"operator\":   \"and\"\n      }\n\t},\n\t\"from\": 0, \n\t\"size\": 30}\n}]]]; nested: JsonParseException[Unexpected character ('{' (code 123)): was expecting either valid name character (for unquoted name) or double-quote (for quoted) to start field name\n at [Source: [B@52afc562; line: 7, column: 3]]; }{[0CTkBM0pQGK1MzYEDlrpcQ][republishan2][3]: SearchParseException[[republishan2][3]: from[-1],size[-1],sort[<custom:\"re_max\": org.elasticsearch.index.fielddata.fieldcomparator.LongValuesComparatorSource@364d93ed>!]: Parse Failure [Failed to parse source [{\n\t\"sort\": {\n\t\t\"re_max\": {\n\t\t\t\"order\": \"desc\"\n\t\t\t}\n\t\t\t}, \n\t{\n      \"multi_match\" : {\n        \"query\":      \"obama world news\",\n        \"type\":       \"cross_fields\",\n        \"fields\":     [ \"Title\", \"Description\" ],\n        \"operator\":   \"and\"\n      }\n\t},\n\t\"from\": 0, \n\t\"size\": 30}\n}]]]; nested: JsonParseException[Unexpected character ('{' (code 123)): was expecting either valid name character (for unquoted name) or double-quote (for quoted) to start field name\n at [Source: [B@52afc562; line: 7, column: 3]]; }{[0CTkBM0pQGK1MzYEDlrpcQ][republishan2][4]: SearchParseException[[republishan2][4]: from[-1],size[-1],sort[<custom:\"re_max\": org.elasticsearch.index.fielddata.fieldcomparator.LongValuesComparatorSource@6e98bb14>!]: Parse Failure [Failed to parse source [{\n\t\"sort\": {\n\t\t\"re_max\": {\n\t\t\t\"order\": \"desc\"\n\t\t\t}\n\t\t\t}, \n\t{\n      \"multi_match\" : {\n        \"query\":      \"obama world news\",\n        \"type\":       \"cross_fields\",\n        \"fields\":     [ \"Title\", \"Description\" ],\n        \"operator\":   \"and\"\n      }\n\t},\n\t\"from\": 0, \n\t\"size\": 30}\n}]]]; nested: JsonParseException[Unexpected character ('{' (code 123)): was expecting either valid name character (for unquoted name) or double-quote (for quoted) to start field name\n at [Source: [B@52afc562; line: 7, column: 3]]; }{[0CTkBM0pQGK1MzYEDlrpcQ][republishan2][1]: SearchParseException[[republishan2][1]: from[-1],size[-1],sort[<custom:\"re_max\": org.elasticsearch.index.fielddata.fieldcomparator.LongValuesComparatorSource@6c0543f7>!]: Parse Failure [Failed to parse source [{\n\t\"sort\": {\n\t\t\"re_max\": {\n\t\t\t\"order\": \"desc\"\n\t\t\t}\n\t\t\t}, \n\t{\n      \"multi_match\" : {\n        \"query\":      \"obama world news\",\n        \"type\":       \"cross_fields\",\n        \"fields\":     [ \"Title\", \"Description\" ],\n        \"operator\":   \"and\"\n      }\n\t},\n\t\"from\": 0, \n\t\"size\": 30}\n}]]]; nested: JsonParseException[Unexpected character ('{' (code 123)): was expecting either valid name character (for unquoted name) or double-quote (for quoted) to start field name\n at [Source: [B@52afc562; line: 7, column: 3]]; }{[0CTkBM0pQGK1MzYEDlrpcQ][republishan2][2]: SearchParseException[[republishan2][2]: from[-1],size[-1],sort[<custom:\"re_max\": org.elasticsearch.index.fielddata.fieldcomparator.LongValuesComparatorSource@215084be>!]: Parse Failure [Failed to parse source [{\n\t\"sort\": {\n\t\t\"re_max\": {\n\t\t\t\"order\": \"desc\"\n\t\t\t}\n\t\t\t}, \n\t{\n      \"multi_match\" : {\n        \"query\":      \"obama world news\",\n        \"type\":       \"cross_fields\",\n        \"fields\":     [ \"Title\", \"Description\" ],\n        \"operator\":   \"and\"\n      }\n\t},\n\t\"from\": 0, \n\t\"size\": 30}\n}]]]; nested: JsonParseException[Unexpected character ('{' (code 123)): was expecting either valid name character (for unquoted name) or double-quote (for quoted) to start field name\n at [Source: [B@52afc562; line: 7, column: 3]]; }]",
    "status": 400
}

我正在使用Postman Rest客户端运行查询。我的代码有什么问题?

黑POP

这样尝试

{
  "query": {
    "multi_match": {
      "query": "obama world news",
      "type": "cross_fields",
      "fields": ["Title", "Description"],
      "operator": "and"
    }
  },
  "from": 0,
  "size": 20,
  "sort": [
    {
      "re_max": {
        "order": "desc"
      }
    }
  ]
}

希望能帮助到你..!

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章