tester
두 가지 유형 items
및 다음과 같은 인덱스 매핑이 있습니다 items_two
.
curl -XPUT 'localhost:9200/tester?pretty=true' -d '{
"mappings": {
"items": {
"properties" : {
"body" : { "type": "string" }
}},
"items_two": {
"properties" : {
"body" : { "type": "string" },
"publised" : { "type": "integer"}
}}}}'
나는 그것에 세 가지 요소를 넣었습니다.
curl -XPUT 'localhost:9200/tester/items/1?pretty=true' -d '{
"body" : "Hey there im reading a book"
}'
curl -XPUT 'localhost:9200/tester/items_two/1?pretty=true' -d '{
"body" : "I love the new book of my brother",
"publised" : 0
}'
curl -XPUT 'localhost:9200/tester/items_two/2?pretty=true' -d '{
"body" : "Stephen kings book is very nice",
"publised" : 1
}'
나는 단어와 일치하는 쿼리해야 book
하고 있습니다 published = 1
AND하지 않은 사람 published
매핑에,하지만이 book
(유일한 항목으로 그것에 items
).
다음 쿼리를 사용하면 "Stephen kings book is very nice"
항목 과 만 일치합니다 (분명히).
curl -XGET 'localhost:9200/tester/_search?pretty=true' -d '{
"query": {
"bool": {
"must": [
{
"match": { "body": "book" }
},
{
"match": { "publised": "1" }
}]
}}}'
나는 문자열을 검색하면 내 원하는 출력이 book
유형의 항목 # 1과 일치해야합니다 items
( "Hey there im reading a book"
)와 item
유형 # 2 items_two
( "Stephen kings book is very nice"
).
매핑 등을 변경하고 싶지 않습니다. 하나의 쿼리를 통해이를 보관해야합니다. 쿼리를 어떻게 작성할 수 있습니까?
미리 감사드립니다.
이러한 종류의 검색에 _type 필드를 사용할 수 있습니다 . 다음 쿼리를 시도하십시오.
{
"query": {
"bool": {
"should": [
{
"bool": {
"must": [
{
"match": {
"body": "text"
}
},
{
"match": {
"publised": "1"
}
}
],
"filter": {
"term": {
"_type": "items_two"
}
}
}
},
{
"bool": {
"must": [
{
"match": {
"body": "text"
}
}
],
"filter": {
"term": {
"_type": "items"
}
}
}
}
]
}
}
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다