내 목적은 여러 필드에서 값을 검색하고이 값과 고유 값의 수를 반환하는 것입니다.여러 필드의 값에 대한 탄성 검색 검색
이렇게하려면 패싯을 사용해야한다는 것을 깨달았습니다.
이
는 데이터베이스 스키마입니다 :index:
analysis:
analyzer:
custom_search_analyzer:
type: custom
tokenizer: standard
filter : [standard, snowball, lowercase, asciifolding]
custom_index_analyzer:
type: custom
tokenizer: standard
filter : [standard, snowball, lowercase, asciifolding, custom_filter]
filter:
custom_filter:
type: edgeNGram
side: front
min_gram: 1
max_gram: 20
{
"structure": {
"properties": {
"name": {"type": "string", "search_analyzer": "custom_search_analyzer", "index_analyzer": "custom_index_analyzer"},
"locality": {"type": "string", "search_analyzer": "custom_search_analyzer", "index_analyzer": "custom_index_analyzer"},
"province": {"type": "string", "search_analyzer": "custom_search_analyzer", "index_analyzer": "custom_index_analyzer"},
"region": {"type": "string", "search_analyzer": "custom_search_analyzer", "index_analyzer": "custom_index_analyzer"}
}
}
}
이 내가 사용하려고 쿼리입니다 : 나는이 작업을 완료 한 모든 시험의
{
"query": {
"bool": {
"should": [
{
"match": {
"locality": "bolo"
}
},
{
"match": {
"region": "bolo"
}
},
{
"match": {
"name": "bolo"
}
}
]
}
},
"facets": {
"region": {
"query": {
"term": {
"region": "bolo"
}
}
},
"locality": {
"query": {
"term": {
"locality": "bolo"
}
}
},
"name": {
"query": {
"term": {
"name": "bolo"
}
}
}
}
}
가장 가까운 쿼리입니다 그러나 나의 원하는 결과에, 나에게 뚜렷한 분야의 수를 말하지 않고, 나는 그것이 총 분야를 세는 것을 발견했다.
facets: {
region: {
_type: query
count: 0
}
locality: {
_type: query
count: 2
}
name: {
_type: query
count: 0
}
}
내가 이런 결과를 가지고 싶다 (안 그래서 분명히 기록 된 정확하지만 내가 필요로하는 것을 이해 않음) :
예를 들어은, 위의 쿼리는 다음 결과를 반환
facets: {
....
locality: {
_type: query
"terms": [
{"term": "Bologna", "count": 1},
{"term": "Bolognano", "count": 1}
]
}
어떻게하면됩니까?
패싯에서 "검색어"대신 "검색어"를 사용하고 연구 분야에 "색인 : not_analyzed"을 넣으려고했으나 정확한 범위가 아니라 부분 만 입력하면 반환됩니다!
내가 제대로 이해한다면, 당신은 단지 하나의 필드와 전체에 대한 모든 분야에 걸쳐 하나의면과 일치하는면 필터를 만들려는 것 -
난 당신이 값 카운트 집계를 찾고 있습니다 믿습니다. – phoet
정확하지는 않지만 모든면에서 총 개수는 반환하지 않지만 검색과 일치하는 필드의 내용과 발견 된 모든 콘텐츠의 수를 알려주십시오. 예를 들어 위에서 썼습니다. 이런 일은'query' 대신에'terms' 패싯을 사용하여 얻습니다.'terms'만이 필드의 정확한 일치를 찾습니다! – Lughino