簡體   English   中英

多個搜索字段 elasticsearphp

[英]Multiple search field elasticsearphp

您好,我想用 elasticsearch 做類似的事情在此處輸入圖像描述

我已經對 elasticsearch 有所了解,但我不明白我該怎么做,多搜索

您可以使用bool/must/should子句的組合來組合多個條件

{
  "query": {
    "bool": {
      "should": [
        {
          "multi_match": {
            "query": "tag"
          }
        },
        {
          "match": {
            "answers": 0
          }
        },
        {
          "match": {
            "user": 1234
          }
        },
        {
          "multi_match": {
            "query": "words here",
            "type": "phrase"
          }
        },
        {
          "match": {
            "score": 3
          }
        },
        {
          "match": {
            "isaccepted": "yes"
          }
        }
      ]
    }
  }
}

如果要搜索多個字段,則可以使用multi_match 查詢

如果未提供任何字段,則 multi_match 查詢默認為 index.query.default_field 索引設置,而后者又默認為 *。 這將提取映射中符合術語查詢條件的所有字段並過濾元數據字段。 然后組合所有提取的字段以構建查詢。

添加帶有索引數據、搜索查詢和搜索結果的工作示例

指數數據:

{
  "answers": 0,
  "isaccepted": "no"
}
{
  "answers": 0,
  "isaccepted": "yes"
}

搜索查詢:

{
  "query": {
    "multi_match" : {
      "query" : "yes"
    }
  }
}

搜索結果:

"hits": [
      {
        "_index": "67542669",
        "_type": "_doc",
        "_id": "1",
        "_score": 0.2876821,
        "_source": {
          "answers": 0,
          "isaccepted": "yes"
        }
      }
    ]

暫無
暫無

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

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