簡體   English   中英

彈性搜索完全匹配查詢

[英]Elastic Search exact match query

我想構造一個與屬性完全匹配的查詢,並接受針對該屬性搜索的多個值。

目前,我正在使用以下查詢來獲取單個文檔的數據。

query = {
    "match_phrase" : {
      "id" : "abc"
    }
};

我想針對id屬性匹配多個值。 就像是

query = {
    "match_phrase" : {
      "id" : ["abc", "xyz"]
    }
};

我想知道什么是等效的上述查詢。

{
  "abc    " : {
    "mappings    " : {
      "keywordsearches    " : {
        "properties    " : {
          "keyword    " : {
            "type    " : "string    "
          },
          "module_name    " : {
            "type    " : "string    "
          },
          "timestamp    " : {
            "type    " : "date    ",
            "format    " : "dateOptionalTime    "
          }
        }
      },
      "npmmodules    " : {
        "properties    " : {
          "author    " : {
            "type    " : "string    "
          },
          "contributors    " : {
            "type    " : "string    "
          },
          "created_at    " : {
            "type    " : "date    ",
            "format    " : "dateOptionalTime    "
          },
          "curatedcontents    " : {
            "properties    " : {
              "description    " : {
                "type    " : "string    "
              },
              "link    " : {
                "type    " : "string    "
              }
            }
          },
          "curatedcontents_count    " : {
            "type    " : "long    "
          },
          "datachanged    " : {
            "type    " : "boolean    "
          },
          "dependencies    " : {
            "properties    " : {
              "name    " : {
                "type    " : "string    "
              },
              "version    " : {
                "type    " : "string    "
              }
            }
          },
          "description    " : {
            "type    " : "string    "
          },
          "downloads    " : {
            "properties    " : {
              "count    " : {
                "type    " : "long    "
              },
              "day    " : {
                "type    " : "date    ",
                "format    " : "dateOptionalTime    "
              }
            }
          },
          "downloads_meta    " : {
            "properties    " : {
              "last_updated    " : {
                "type    " : "date    ",
                "format    " : "dateOptionalTime    "
              }
            }
          },
          "fork    " : {
            "type    " : "boolean    "
          },
          "full_name    " : {
            "type    " : "string    "
          },
          "gh_meta    " : {
            "properties    " : {
              "blacklist    " : {
                "properties    " : {
                  "repo    " : {
                    "type    " : "string    "
                  },
                  "user    " : {
                    "type    " : "string    "
                  }
                }
              },
              "etag    " : {
                "type    " : "string    "
              },
              "last-modified    " : {
                "type    " : "string    "
              }
            }
          },
          "git_url    " : {
            "type    " : "string    "
          },
          "homepage    " : {
            "type    " : "string    "
          },
          "html_url    " : {
            "type    " : "string    "
          },
          "id    " : {
            "type    " : "string    "
          },
          "keywords    " : {
            "type    " : "string    "
          },
          "latest    " : {
            "type    " : "string    "
          },
          "licenses    " : {
            "properties    " : {
              "MIT    " : {
                "type    " : "string    "
              },
              "covers    " : {
                "type    " : "string    "
              },
              "description    " : {
                "type    " : "string    "
              },
              "file    " : {
                "type    " : "string    "
              },
              "license    " : {
                "type    " : "string    "
              },
              "link    " : {
                "type    " : "string    "
              },
              "name    " : {
                "type    " : "string    "
              },
              "type    " : {
                "type    " : "string    "
              },
              "type:    " : {
                "type    " : "string    "
              },
              "ur    " : {
                "type    " : "string    "
              },
              "url    " : {
                "type    " : "string    "
              },
              "version    " : {
                "type    " : "string    "
              }
            }
          },
          "maintainers    " : {
            "type    " : "string    "
          },
          "name    " : {
            "type    " : "string    "
          },
          "npm_meta    " : {
            "properties    " : {
              "etag    " : {
                "type    " : "string    "
              },
              "last-modified    " : {
                "type    " : "date    ",
                "format    " : "dateOptionalTime    "
              }
            }
          },
          "npm_stars    " : {
            "type    " : "long    "
          },
          "open_issues_count    " : {
            "type    " : "long    "
          },
          "pushed_at    " : {
            "type    " : "date    ",
            "format    " : "dateOptionalTime    "
          },
          "rank    " : {
            "type    " : "double    "
          },
          "readme    " : {
            "type    " : "string    "
          },
          "releases    " : {
            "properties    " : {
              "time    " : {
                "type    " : "date    ",
                "format    " : "dateOptionalTime    "
              },
              "version    " : {
                "type    " : "string    "
              }
            }
          },
          "repository    " : {
            "properties    " : {
              "author    " : {
                "type    " : "string    "
              },
              "bugs    " : {
                "type    " : "string    "
              },
              "commit_date    " : {
                "type    " : "date    ",
                "format    " : "dateOptionalTime    "
              },
              "description    " : {
                "type    " : "string    "
              },
              "dist    " : {
                "type    " : "string    "
              },
              "git    " : {
                "type    " : "string    "
              },
              "github    " : {
                "type    " : "string    "
              },
              "handle    " : {
                "type    " : "string    "
              },
              "homepage    " : {
                "type    " : "string    "
              },
              "id_string    " : {
                "type    " : "string    "
              },
              "job    " : {
                "type    " : "string    "
              },
              "main    " : {
                "type    " : "string    "
              },
              "path    " : {
                "type    " : "string    "
              },
              "private    " : {
                "type    " : "string    "
              },
              "repository    " : {
                "type    " : "string    "
              },
              "revision    " : {
                "type    " : "string    "
              },
              "static    " : {
                "type    " : "string    "
              },
              "title    " : {
                "type    " : "string    "
              },
              "tyep    " : {
                "type    " : "string    "
              },
              "typ    " : {
                "type    " : "string    "
              },
              "type    " : {
                "type    " : "string    "
              },
              "type:    " : {
                "type    " : "string    "
              },
              "update    " : {
                "type    " : "string    "
              },
              "ur    " : {
                "type    " : "string    "
              },
              "url    " : {
                "type    " : "string    "
              },
              "web    " : {
                "type    " : "string    "
              },
              "web     " : {
                "type    " : "string    "
              }
            }
          },
          "rev    " : {
            "type    " : "string    "
          },
          "stargazers_count    " : {
            "type    " : "long    "
          },
          "subscribers_count    " : {
            "type    " : "long    "
          },
          "updated_at    " : {
            "type    " : "date    ",
            "format    " : "dateOptionalTime    "
          },
          "userreviews    " : {
            "properties    " : {
              "review    " : {
                "type    " : "string    "
              },
              "timestamp    " : {
                "type    " : "date    ",
                "format    " : "dateOptionalTime    "
              }
            }
          },
          "version    " : {
            "type    " : "string    "
          },
          "watchers_count    " : {
            "type    " : "long    "
          }
        }
      },
      "npmusers    " : {
        "properties    " : {
          "blog    " : {
            "type    " : "string    "
          },
          "created_at    " : {
            "type    " : "date    ",
            "format    " : "dateOptionalTime    "
          },
          "email    " : {
            "type    " : "string    "
          },
          "followers    " : {
            "type    " : "long    "
          },
          "following    " : {
            "type    " : "long    "
          },
          "gh_meta    " : {
            "properties    " : {
              "blacklist    " : {
                "properties    " : {
                  "user    " : {
                    "type    " : "string    "
                  }
                }
              },
              "etag    " : {
                "type    " : "string    "
              },
              "last-modified    " : {
                "type    " : "string    "
              }
            }
          },
          "github    " : {
            "type    " : "string    "
          },
          "html_url    " : {
            "type    " : "string    "
          },
          "id    " : {
            "type    " : "string    "
          },
          "name    " : {
            "type    " : "string    "
          },
          "npm_meta    " : {
            "properties    " : {
              "etag    " : {
                "type    " : "string    "
              },
              "last-updated    " : {
                "type    " : "date    ",
                "format    " : "dateOptionalTime    "
              }
            }
          },
          "public_gists    " : {
            "type    " : "long    "
          },
          "public_repos    " : {
            "type    " : "long    "
          },
          "type    " : {
            "type    " : "string    "
          },
          "updated_at    " : {
            "type    " : "date    ",
            "format    " : "dateOptionalTime    "
          }
        }
      }
    }
  }
}

您可以使用布爾查詢。

{
    "bool" : {            
        "should" : [
            {"match_phrase" : {"id" : "abc" }},
            {"match_phrase" : {"id" : "xyz" }}
        ],
        "minimum_should_match" : 1            
    }
}

使用條款查詢:

 {
  "query": {
 "terms": {
  "id": [
    "abc",
    "xyz"
   ]
  }
 } 
}

希望能幫助到你!

最后,我最終使用了mget,它為文檔中的任何屬性提供了精確匹配

{
    "index" : "index",
    "type" : "type",
    "body" : {
        "attribute_name" : "attribute_value"
    }
}

暫無
暫無

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

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