簡體   English   中英

彈性搜索多個字段中的多個關鍵字

[英]Elastic search multiple keywords in multiple fields

我正在嘗試在彈性搜索中構建查詢以在多個字段的文本內搜索,例如:標題和描述是字段,我想在這3個字段中搜索“obama”,“world”,“news”。 我試着在Elastic網站上搜索並找到信息:
http://www.elasticsearch.org/guide/en/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客戶端來運行查詢。 我的代碼有什么問題?

試試這樣吧

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

希望能幫助到你..!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM